diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-14 18:03:47 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-14 18:03:47 +0000 |
commit | 08a3b713ae113c58893e7daddbbc4afd178d446f (patch) | |
tree | d2f1dee12be5cb34f4acdc1cf269021e5948a7ef /views | |
parent | 56008bf3dc79ab9d76f09769317ac4307c385b08 (diff) | |
download | chromium_src-08a3b713ae113c58893e7daddbbc4afd178d446f.zip chromium_src-08a3b713ae113c58893e7daddbbc4afd178d446f.tar.gz chromium_src-08a3b713ae113c58893e7daddbbc4afd178d446f.tar.bz2 |
Fixes regression in menu button. I converted a call from GetWidget to
GetWindow, the problem is in certain scenarios GetWindow can return
null. I've changed the code back to GetWidget and converted Screen
from taking a NativeWindow to a NativeView.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/269076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28986 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/button/menu_button.cc | 4 | ||||
-rw-r--r-- | views/screen.h | 4 | ||||
-rw-r--r-- | views/screen_gtk.cc | 11 | ||||
-rw-r--r-- | views/view.h | 3 | ||||
-rw-r--r-- | views/window/window_gtk.cc | 2 |
5 files changed, 15 insertions, 9 deletions
diff --git a/views/controls/button/menu_button.cc b/views/controls/button/menu_button.cc index 7f1daf7..5dc59cb 100644 --- a/views/controls/button/menu_button.cc +++ b/views/controls/button/menu_button.cc @@ -103,13 +103,13 @@ void MenuButton::Paint(gfx::Canvas* canvas, bool for_drag) { //////////////////////////////////////////////////////////////////////////////// int MenuButton::GetMaximumScreenXCoordinate() { - if (!GetWindow()) { + if (!GetWidget()) { NOTREACHED(); return 0; } gfx::Rect monitor_bounds = - Screen::GetMonitorWorkAreaNearestWindow(GetWindow()->GetNativeWindow()); + Screen::GetMonitorWorkAreaNearestWindow(GetWidget()->GetNativeView()); return monitor_bounds.right() - 1; } diff --git a/views/screen.h b/views/screen.h index 0c0d940..f7c023c 100644 --- a/views/screen.h +++ b/views/screen.h @@ -19,10 +19,10 @@ class Screen { static gfx::Point GetCursorScreenPoint(); // Returns the work area of the monitor nearest the specified window. - static gfx::Rect GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window); + static gfx::Rect GetMonitorWorkAreaNearestWindow(gfx::NativeView view); // Returns the bounds of the monitor nearest the specified window. - static gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeWindow window); + static gfx::Rect GetMonitorAreaNearestWindow(gfx::NativeView view); // Returns the monitor area (not the work area, but the complete bounds) of // the monitor nearest the specified point. diff --git a/views/screen_gtk.cc b/views/screen_gtk.cc index dea117c..9302853 100644 --- a/views/screen_gtk.cc +++ b/views/screen_gtk.cc @@ -31,16 +31,19 @@ gfx::Rect static GetPrimaryMonitorBounds() { } // static -gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window) { - // TODO(beng): use |window|. +gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeView view) { + // TODO(beng): use |view|. return GetPrimaryMonitorBounds(); } // static -gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeWindow window) { +gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeView view) { + GtkWidget* top_level = gtk_widget_get_toplevel(view); + DCHECK(GTK_IS_WINDOW(top_level)); + GtkWindow* window = GTK_WINDOW(top_level); GdkScreen* screen = gtk_window_get_screen(window); gint monitor_num = gdk_screen_get_monitor_at_window(screen, - (GTK_WIDGET(window))->window); + top_level->window); GdkRectangle bounds; gdk_screen_get_monitor_geometry(screen, monitor_num, &bounds); return gfx::Rect(bounds); diff --git a/views/view.h b/views/view.h index cb44e2a..dd7662b 100644 --- a/views/view.h +++ b/views/view.h @@ -428,6 +428,9 @@ class View : public AcceleratorTarget { virtual Widget* GetWidget() const; // Gets the Widget that most closely contains this View, if any. + // NOTE: almost all views displayed on screen have a Widget, but not + // necessarily a Window. This is due to widgets being able to create top + // level windows (as is done for popups, bubbles and menus). virtual Window* GetWindow() const; // Get the containing RootView diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index 8f64a5b3..a3a3192 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -442,7 +442,7 @@ void WindowGtk::SizeWindowToDefault(GtkWindow* parent) { center_rect = gfx::Rect(parent_x, parent_y, parent_w, parent_h); } else { // We have no parent window, center over the screen. - center_rect = Screen::GetMonitorWorkAreaNearestWindow(GetNativeWindow()); + center_rect = Screen::GetMonitorWorkAreaNearestWindow(GetNativeView()); } gfx::Size size = non_client_view_->GetPreferredSize(); gfx::Rect bounds(center_rect.x() + (center_rect.width() - size.width()) / 2, |