From ff26c3c16f093864528c7a3a207a0d55d80995d6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 28 Nov 2014 15:59:03 +0800 Subject: [PATCH] Some coding style fixes --- atom/browser/api/atom_api_menu_mac.mm | 22 +++++++++++++++------- atom/browser/api/atom_api_menu_views.cc | 19 +++++++++++++------ atom/browser/api/atom_api_menu_views.h | 3 ++- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/atom/browser/api/atom_api_menu_mac.mm b/atom/browser/api/atom_api_menu_mac.mm index 9b1652939378..e63b07324bce 100644 --- a/atom/browser/api/atom_api_menu_mac.mm +++ b/atom/browser/api/atom_api_menu_mac.mm @@ -19,13 +19,17 @@ MenuMac::MenuMac() { } void MenuMac::Popup(Window* window) { + NativeWindow* native_window = window->window(); + if (!native_window) + return; + content::WebContents* web_contents = native_window->GetWebContents(); + if (!web_contents) + return; + + NSWindow* nswindow = native_window->GetNativeWindow(); base::scoped_nsobject menu_controller( [[AtomMenuController alloc] initWithModel:model_.get()]); - NativeWindow* native_window = window->window(); - NSWindow* nswindow = native_window->GetNativeWindow(); - content::WebContents* web_contents = native_window->GetWebContents(); - // Fake out a context menu event. NSEvent* currentEvent = [NSApp currentEvent]; NSPoint position = [nswindow mouseLocationOutsideOfEventStream]; @@ -47,13 +51,17 @@ void MenuMac::Popup(Window* window) { } void MenuMac::PopupAt(Window* window, int x, int y) { - base::scoped_nsobject menu_controller( - [[AtomMenuController alloc] initWithModel:model_.get()]); - NativeWindow* native_window = window->window(); + if (!native_window) + return; content::WebContents* web_contents = native_window->GetWebContents(); + if (!web_contents) + return; + NSView* view = web_contents->GetContentNativeView(); NSMenu* menu = [menu_controller menu]; + base::scoped_nsobject menu_controller( + [[AtomMenuController alloc] initWithModel:model_.get()]); // Show the menu. [menu popUpMenuPositioningItem:[menu itemAtIndex:0] diff --git a/atom/browser/api/atom_api_menu_views.cc b/atom/browser/api/atom_api_menu_views.cc index c8c7ceb50acb..b06a1e79cbe0 100644 --- a/atom/browser/api/atom_api_menu_views.cc +++ b/atom/browser/api/atom_api_menu_views.cc @@ -21,14 +21,21 @@ void MenuViews::Popup(Window* window) { } void MenuViews::PopupAt(Window* window, int x, int y) { - NativeWindow* nativeWindowViews = - static_cast(window->window()); - gfx::Point viewOrigin = nativeWindowViews->GetWebContents() - ->GetRenderWidgetHostView()->GetViewBounds().origin(); - PopupAtPoint(window, gfx::Point(viewOrigin.x() + x, viewOrigin.y() + y)); + NativeWindow* native_window = static_cast(window->window()); + if (!native_window) + return; + content::WebContents* web_contents = native_window->GetWebContents(); + if (!web_contents) + return; + content::RenderWidgetHostView* view = web_contents->GetRenderWidgetHostView(); + if (!view) + return; + + gfx::Point origin = view->GetViewBounds().origin(); + PopupAtPoint(window, gfx::Point(origin.x() + x, origin.y() + y)); } -void MenuViews::PopupAtPoint(Window* window, gfx::Point point) { +void MenuViews::PopupAtPoint(Window* window, const gfx::Point& point) { views::MenuRunner menu_runner( model(), views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS); diff --git a/atom/browser/api/atom_api_menu_views.h b/atom/browser/api/atom_api_menu_views.h index fa375fcba172..47df508ff988 100644 --- a/atom/browser/api/atom_api_menu_views.h +++ b/atom/browser/api/atom_api_menu_views.h @@ -21,7 +21,8 @@ class MenuViews : public Menu { virtual void PopupAt(Window* window, int x, int y) OVERRIDE; private: - void PopupAtPoint(Window* window, gfx::Point point); + void PopupAtPoint(Window* window, const gfx::Point& point); + DISALLOW_COPY_AND_ASSIGN(MenuViews); };