diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-01 00:07:00 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-01 00:07:00 +0000 |
commit | a2920638f52df5d5e0e3ea86c1802d4a7416abe5 (patch) | |
tree | 635245f5d524df6ce6a10ec75db72f81639a4156 | |
parent | fb3ef9384cc76c4237f98e5aa38d2689cc7b60cd (diff) | |
download | chromium_src-a2920638f52df5d5e0e3ea86c1802d4a7416abe5.zip chromium_src-a2920638f52df5d5e0e3ea86c1802d4a7416abe5.tar.gz chromium_src-a2920638f52df5d5e0e3ea86c1802d4a7416abe5.tar.bz2 |
Status bubble limping in TOOLKIT_VIEWS.
Add CreateTransparentFloatingWidget method to Widget and add Init/SetContentsView methods.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/160474
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22229 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/frame/browser_view.cc | 26 | ||||
-rw-r--r-- | chrome/browser/views/status_bubble_views.cc | 62 | ||||
-rw-r--r-- | views/screen.h | 5 | ||||
-rw-r--r-- | views/screen_gtk.cc | 17 | ||||
-rw-r--r-- | views/screen_win.cc | 9 | ||||
-rw-r--r-- | views/widget/root_view.cc | 27 | ||||
-rw-r--r-- | views/widget/root_view.h | 4 | ||||
-rw-r--r-- | views/widget/widget.h | 19 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 124 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 8 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 40 | ||||
-rw-r--r-- | views/widget/widget_win.h | 17 | ||||
-rw-r--r-- | views/window/window_gtk.cc | 16 |
13 files changed, 189 insertions, 185 deletions
diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index d4fc97e..c9a3155 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -4,10 +4,6 @@ #include "chrome/browser/views/frame/browser_view.h" -#if defined(OS_LINUX) -#include <gtk/gtk.h> -#endif - #include "app/drag_drop_types.h" #include "app/gfx/canvas.h" #include "app/l10n_util.h" @@ -27,9 +23,6 @@ #include "chrome/browser/download/download_manager.h" #include "chrome/browser/find_bar.h" #include "chrome/browser/find_bar_controller.h" -#if defined(OS_WIN) -#include "chrome/browser/jumplist.h" -#endif #include "chrome/browser/page_info_window.h" #include "chrome/browser/profile.h" #include "chrome/browser/view_ids.h" @@ -63,21 +56,24 @@ #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "grit/webkit_resources.h" -#if defined(OS_WIN) -#include "views/controls/scrollbar/native_scroll_bar.h" -#endif #include "views/controls/single_split_view.h" #include "views/fill_layout.h" #include "views/focus/external_focus_tracker.h" #include "views/view.h" #include "views/widget/root_view.h" #include "views/window/dialog_delegate.h" -#if !defined(OS_WIN) -#include "views/window/hit_test.h" -#endif #include "views/window/non_client_view.h" #include "views/window/window.h" +#if defined(OS_WIN) +#include "chrome/browser/jumplist.h" +#include "views/controls/scrollbar/native_scroll_bar.h" +#elif defined(OS_LINUX) +#include <gtk/gtk.h> + +#include "views/window/hit_test.h" +#endif + using base::TimeDelta; // static @@ -641,11 +637,7 @@ BrowserWindowTesting* BrowserView::GetBrowserWindowTesting() { } StatusBubble* BrowserView::GetStatusBubble() { -#if defined(OS_WIN) return status_bubble_.get(); -#else - return NULL; -#endif } void BrowserView::SelectedTabToolbarSizeChanged(bool is_animating) { diff --git a/chrome/browser/views/status_bubble_views.cc b/chrome/browser/views/status_bubble_views.cc index 500a274..cb8c589 100644 --- a/chrome/browser/views/status_bubble_views.cc +++ b/chrome/browser/views/status_bubble_views.cc @@ -9,9 +9,6 @@ #include "app/gfx/canvas.h" #include "app/gfx/text_elider.h" #include "app/l10n_util.h" -#if defined(OS_WIN) -#include "app/l10n_util_win.h" -#endif #include "app/animation.h" #include "app/resource_bundle.h" #include "base/message_loop.h" @@ -25,11 +22,10 @@ #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkRect.h" #include "views/controls/label.h" +#include "views/screen.h" #include "views/widget/root_view.h" #include "views/widget/widget.h" -#if defined(OS_WIN) -#include "views/widget/widget_win.h" -#endif +#include "views/window/window.h" // The alpha and color of the bubble's shadow. static const SkColor kShadowColor = SkColorSetARGB(30, 0, 0, 0); @@ -466,26 +462,14 @@ StatusBubbleViews::~StatusBubbleViews() { void StatusBubbleViews::Init() { if (!popup_.get()) { -#if defined(OS_WIN) - views::WidgetWin* popup = new views::WidgetWin; - popup->set_delete_on_destroy(false); - + popup_.reset(views::Widget::CreateTransparentPopupWidget(false)); if (!view_) - view_ = new StatusView(this, popup, frame_->GetThemeProvider()); - - popup->set_window_style(WS_POPUP); - popup->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW | - WS_EX_TRANSPARENT | - l10n_util::GetExtendedTooltipStyles()); - popup->SetOpacity(0x00); - popup->Init(frame_->GetNativeView(), gfx::Rect()); - popup->SetContentsView(view_); + view_ = new StatusView(this, popup_.get(), frame_->GetThemeProvider()); + popup_->SetOpacity(0x00); + popup_->Init(frame_->GetNativeView(), gfx::Rect()); + popup_->SetContentsView(view_); Reposition(); - popup->Show(); - popup_.reset(popup); -#else - NOTIMPLEMENTED(); -#endif + popup_->Show(); } } @@ -589,24 +573,17 @@ void StatusBubbleViews::UpdateDownloadShelfVisibility(bool visible) { } void StatusBubbleViews::AvoidMouse() { - // Our status bubble is located in screen coordinates, so we should get - // those rather than attempting to reverse decode the web contents - // coordinates. - gfx::Point cursor_location; -#if defined(OS_WIN) - POINT tmp = { 0, 0 }; - GetCursorPos(&tmp); - cursor_location = tmp; -#else - NOTIMPLEMENTED(); -#endif - // Get the position of the frame. gfx::Point top_left; views::RootView* root = frame_->GetRootView(); views::View::ConvertPointToScreen(root, &top_left); int window_width = root->GetLocalBounds(true).width(); // border included. + // Our status bubble is located in screen coordinates, so we should get + // those rather than attempting to reverse decode the web contents + // coordinates. + gfx::Point cursor_location = views::Screen::GetCursorScreenPoint(); + // Get the cursor position relative to the popup. if (view_->UILayoutIsRightToLeft()) { int top_right_x = top_left.x() + window_width; @@ -648,16 +625,9 @@ void StatusBubbleViews::AvoidMouse() { // Check if the bubble sticks out from the monitor or will obscure // download shelf. -#if defined(OS_WIN) - MONITORINFO monitor_info; - monitor_info.cbSize = sizeof(monitor_info); - GetMonitorInfo(MonitorFromWindow(frame_->GetNativeView(), - MONITOR_DEFAULTTONEAREST), &monitor_info); - gfx::Rect monitor_rect(monitor_info.rcWork); -#else - gfx::Rect monitor_rect; - NOTIMPLEMENTED(); -#endif + gfx::NativeWindow window = frame_->GetWindow()->GetNativeWindow(); + gfx::Rect monitor_rect = + views::Screen::GetMonitorWorkAreaNearestWindow(window); const int bubble_bottom_y = top_left.y() + position_.y() + size_.height(); if (bubble_bottom_y + offset > monitor_rect.height() || diff --git a/views/screen.h b/views/screen.h index eed83bf..c4e5bd6 100644 --- a/views/screen.h +++ b/views/screen.h @@ -5,7 +5,9 @@ #ifndef VIEWS_SCREEN_H_ #define VIEWS_SCREEN_H_ +#include "base/gfx/native_widget_types.h" #include "base/gfx/point.h" +#include "base/gfx/rect.h" namespace views { @@ -15,6 +17,9 @@ namespace views { class Screen { public: static gfx::Point GetCursorScreenPoint(); + + // Returns the work area of the monitor nearest the specified window. + static gfx::Rect GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window); }; } // namespace views diff --git a/views/screen_gtk.cc b/views/screen_gtk.cc index efb8775..22aaa44 100644 --- a/views/screen_gtk.cc +++ b/views/screen_gtk.cc @@ -6,6 +6,8 @@ #include <gtk/gtk.h> +#include "base/logging.h" + namespace views { // static @@ -15,5 +17,20 @@ gfx::Point Screen::GetCursorScreenPoint() { return gfx::Point(x, y); } +// static +gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window) { + // TODO(beng): use |window|. + guchar* raw_data = NULL; + gint data_len = 0; + gboolean success = gdk_property_get(gdk_get_default_root_window(), + gdk_atom_intern("_NET_WORKAREA", FALSE), + gdk_atom_intern("CARDINAL", FALSE), + 0, 0xFF, false, NULL, NULL, &data_len, + &raw_data); + DCHECK(success); + glong* data = reinterpret_cast<glong*>(raw_data); + return gfx::Rect(data[0], data[1], data[0] + data[2], data[1] + data[3]); +} + } // namespace diff --git a/views/screen_win.cc b/views/screen_win.cc index 04191af..b6e7a15 100644 --- a/views/screen_win.cc +++ b/views/screen_win.cc @@ -15,5 +15,14 @@ gfx::Point Screen::GetCursorScreenPoint() { return gfx::Point(pt); } +// static +gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeWindow window) { + MONITORINFO monitor_info; + monitor_info.cbSize = sizeof(monitor_info); + GetMonitorInfo(MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST), + &monitor_info); + return gfx::Rect(monitor_info.rcWork); +} + } // namespace diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index 34de509..145de92 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -8,17 +8,17 @@ #include "app/drag_drop_types.h" #include "app/gfx/canvas.h" -#if defined(OS_WIN) -#include "base/base_drag_source.h" -#endif #include "base/logging.h" #include "base/message_loop.h" +#include "views/fill_layout.h" #include "views/focus/view_storage.h" +#include "views/widget/widget.h" +#include "views/window/window.h" + #if defined(OS_WIN) +#include "base/base_drag_source.h" #include "views/widget/root_view_drop_target.h" #endif -#include "views/widget/widget.h" -#include "views/window/window.h" namespace views { @@ -92,6 +92,23 @@ RootView::~RootView() { pending_paint_task_->Cancel(); // Ensure we're not called any more. } +void RootView::SetContentsView(View* contents_view) { + DCHECK(contents_view && GetWidget()->GetNativeView()) << + "Can't be called until after the native view is created!"; + // The ContentsView must be set up _after_ the window is created so that its + // Widget pointer is valid. + SetLayoutManager(new FillLayout); + if (GetChildViewCount() != 0) + RemoveAllChildViews(true); + AddChildView(contents_view); + + // Force a layout now, since the attached hierarchy won't be ready for the + // containing window's bounds. Note that we call Layout directly rather than + // calling the widget's size changed handler, since the RootView's bounds may + // not have changed, which will cause the Layout not to be done otherwise. + Layout(); +} + ///////////////////////////////////////////////////////////////////////////// // // RootView - layout, painting diff --git a/views/widget/root_view.h b/views/widget/root_view.h index 6488de5..8e8d467 100644 --- a/views/widget/root_view.h +++ b/views/widget/root_view.h @@ -42,6 +42,10 @@ class RootView : public View, virtual ~RootView(); + // Sets the "contents view" of the RootView. This is the single child view + // that is responsible for laying out the contents of the widget. + void SetContentsView(View* contents_view); + // Layout and Painting functions // Overridden from View to implement paint scheduling. diff --git a/views/widget/widget.h b/views/widget/widget.h index f7170da..f3a8613 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -43,6 +43,25 @@ class Widget { public: virtual ~Widget() { } + // Creates a transparent popup widget specific to the current platform useful + // for transient status notifications. + static Widget* CreateTransparentPopupWidget(bool delete_on_destroy); + + // Initialize the Widget with a parent and an initial desired size. + // |contents_view| is the view that will be the single child of RootView + // within this Widget. As contents_view is inserted into RootView's tree, + // RootView assumes ownership of this view and cleaning it up. If you remove + // this view, you are responsible for its destruction. If this value is NULL, + // the caller is responsible for populating the RootView, and sizing its + // contents as the window is sized. + virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds) = 0; + + // Sets the specified view as the contents of this Widget. There can only + // be one contnets view child of this Widget's RootView. This view is sized to + // fit the entire size of the RootView. The RootView takes ownership of this + // View, unless it is set as not being parent-owned. + virtual void SetContentsView(View* view) = 0; + // Returns the bounds of this Widget in the screen coordinate system. // If the receiving Widget is a frame which is larger than its client area, // this method returns the client area if including_frame is false and the diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 677e58c..76abe93 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -6,7 +6,6 @@ #include "app/gfx/path.h" #include "base/compiler_specific.h" -#include "views/fill_layout.h" #include "views/widget/default_theme_provider.h" #include "views/widget/root_view.h" #include "views/widget/tooltip_manager_gtk.h" @@ -78,6 +77,53 @@ WidgetGtk::~WidgetGtk() { MessageLoopForUI::current()->RemoveObserver(this); } +bool WidgetGtk::MakeTransparent() { + // Transparency can only be enabled for windows/popups and only if we haven't + // realized the widget. + DCHECK(!widget_ && type_ != TYPE_CHILD); + + if (!gdk_screen_is_composited(gdk_screen_get_default())) { + // Transparency is only supported for compositing window managers. + DLOG(WARNING) << "compsiting not supported"; + return false; + } + + if (!gdk_screen_get_rgba_colormap(gdk_screen_get_default())) { + // We need rgba to make the window transparent. + return false; + } + + transparent_ = true; + return true; +} + +void WidgetGtk::AddChild(GtkWidget* child) { + gtk_container_add(GTK_CONTAINER(window_contents_), child); +} + +void WidgetGtk::RemoveChild(GtkWidget* child) { + // We can be called after the contents widget has been destroyed, e.g. any + // NativeViewHost not removed from the view hierarchy before the window is + // closed. + if (GTK_IS_CONTAINER(window_contents_)) + gtk_container_remove(GTK_CONTAINER(window_contents_), child); +} + +void WidgetGtk::ReparentChild(GtkWidget* child) { + gtk_widget_reparent(child, window_contents_); +} + +void WidgetGtk::PositionChild(GtkWidget* child, int x, int y, int w, int h) { + GtkAllocation alloc = { x, y, w, h }; + // For some reason we need to do both of these to size a widget. + gtk_widget_size_allocate(child, &alloc); + gtk_widget_set_size_request(child, w, h); + gtk_fixed_move(GTK_FIXED(window_contents_), child, x, y); +} + +//////////////////////////////////////////////////////////////////////////////// +// WidgetGtk, Widget implementation: + void WidgetGtk::Init(GtkWidget* parent, const gfx::Rect& bounds) { // Force creation of the RootView if it hasn't been created yet. @@ -183,72 +229,10 @@ void WidgetGtk::Init(GtkWidget* parent, } } -bool WidgetGtk::MakeTransparent() { - // Transparency can only be enabled for windows/popups and only if we haven't - // realized the widget. - DCHECK(!widget_ && type_ != TYPE_CHILD); - - if (!gdk_screen_is_composited(gdk_screen_get_default())) { - // Transparency is only supported for compositing window managers. - DLOG(WARNING) << "compsiting not supported"; - return false; - } - - if (!gdk_screen_get_rgba_colormap(gdk_screen_get_default())) { - // We need rgba to make the window transparent. - return false; - } - - transparent_ = true; - return true; -} - -void WidgetGtk::AddChild(GtkWidget* child) { - gtk_container_add(GTK_CONTAINER(window_contents_), child); -} - -void WidgetGtk::RemoveChild(GtkWidget* child) { - // We can be called after the contents widget has been destroyed, e.g. any - // NativeViewHost not removed from the view hierarchy before the window is - // closed. - if (GTK_IS_CONTAINER(window_contents_)) - gtk_container_remove(GTK_CONTAINER(window_contents_), child); -} - -void WidgetGtk::ReparentChild(GtkWidget* child) { - gtk_widget_reparent(child, window_contents_); -} - -void WidgetGtk::PositionChild(GtkWidget* child, int x, int y, int w, int h) { - GtkAllocation alloc = { x, y, w, h }; - // For some reason we need to do both of these to size a widget. - gtk_widget_size_allocate(child, &alloc); - gtk_widget_set_size_request(child, w, h); - gtk_fixed_move(GTK_FIXED(window_contents_), child, x, y); -} - void WidgetGtk::SetContentsView(View* view) { - DCHECK(view && widget_) - << "Can't be called until after the HWND is created!"; - // The ContentsView must be set up _after_ the window is created so that its - // Widget pointer is valid. - root_view_->SetLayoutManager(new FillLayout); - if (root_view_->GetChildViewCount() != 0) - root_view_->RemoveAllChildViews(true); - root_view_->AddChildView(view); - - DCHECK(widget_); // Widget must have been created by now. - - // Force a layout now, since the attached hierarchy won't be ready for the - // containing window's bounds. Note that we call Layout directly rather than - // calling OnSizeAllocate, since the RootView's bounds may not have changed, - // which will cause the Layout not to be done otherwise. - root_view_->Layout(); + root_view_->SetContentsView(view); } -//////////////////////////////////////////////////////////////////////////////// -// WidgetGtk, Widget implementation: - void WidgetGtk::GetBounds(gfx::Rect* out, bool including_frame) const { DCHECK(widget_); @@ -841,4 +825,16 @@ void WidgetGtk::HandleGrabBroke() { } } + +//////////////////////////////////////////////////////////////////////////////// +// Widget, public: + +// static +Widget* Widget::CreateTransparentPopupWidget(bool delete_on_destroy) { + WidgetGtk* popup = new WidgetGtk(WidgetGtk::TYPE_POPUP); + popup->set_delete_on_destroy(delete_on_destroy); + popup->MakeTransparent(); + return popup; +} + } // namespace views diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index fbb6c0e..42ea283 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -38,10 +38,6 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer { explicit WidgetGtk(Type type); virtual ~WidgetGtk(); - // Initializes this widget. - void Init(GtkWidget* parent, - const gfx::Rect& bounds); - // Makes the background of the window totally transparent. This must be // invoked before Init. This does a couple of checks and returns true if // the window can be made transparent. The actual work of making the window @@ -75,9 +71,9 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer { // |widget_|. GtkWidget* window_contents() const { return window_contents_; } - virtual void SetContentsView(View* view); - // Overridden from Widget: + virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); + virtual void SetContentsView(View* view); virtual void GetBounds(gfx::Rect* out, bool including_frame) const; virtual void SetBounds(const gfx::Rect& bounds); virtual void SetShape(const gfx::Path& shape); diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index ed58ae9..1f49d1d 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -6,13 +6,13 @@ #include "app/gfx/canvas.h" #include "app/gfx/path.h" +#include "app/l10n_util_win.h" #include "app/win_util.h" #include "base/gfx/native_theme.h" #include "base/string_util.h" #include "base/win_util.h" #include "views/accessibility/view_accessibility.h" #include "views/controls/native_control_win.h" -#include "views/fill_layout.h" #include "views/focus/focus_util_win.h" #include "views/views_delegate.h" #include "views/widget/aero_tooltip_manager.h" @@ -154,7 +154,10 @@ WidgetWin::~WidgetWin() { MessageLoopForUI::current()->RemoveObserver(this); } -void WidgetWin::Init(HWND parent, const gfx::Rect& bounds) { +/////////////////////////////////////////////////////////////////////////////// +// Widget implementation: + +void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) { if (window_style_ == 0) window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; @@ -218,24 +221,9 @@ void WidgetWin::Init(HWND parent, const gfx::Rect& bounds) { } void WidgetWin::SetContentsView(View* view) { - DCHECK(view && hwnd_) << "Can't be called until after the HWND is created!"; - // The ContentsView must be set up _after_ the window is created so that its - // Widget pointer is valid. - root_view_->SetLayoutManager(new FillLayout); - if (root_view_->GetChildViewCount() != 0) - root_view_->RemoveAllChildViews(true); - root_view_->AddChildView(view); - - // Force a layout now, since the attached hierarchy won't be ready for the - // containing window's bounds. Note that we call Layout directly rather than - // calling ChangeSize, since the RootView's bounds may not have changed, which - // will cause the Layout not to be done otherwise. - root_view_->Layout(); + root_view_->SetContentsView(view); } -/////////////////////////////////////////////////////////////////////////////// -// Widget implementation: - void WidgetWin::GetBounds(gfx::Rect* out, bool including_frame) const { CRect crect; if (including_frame) { @@ -1088,4 +1076,20 @@ void WidgetWin::PostProcessActivateMessage(WidgetWin* widget, widget->focus_manager_->RestoreFocusedView(); } } + +//////////////////////////////////////////////////////////////////////////////// +// Widget, public: + +// static +Widget* Widget::CreateTransparentPopupWidget(bool delete_on_destroy) { + WidgetWin* popup = new WidgetWin; + popup->set_window_style(WS_POPUP); + popup->set_window_ex_style(WS_EX_LAYERED | WS_EX_TOOLWINDOW | + WS_EX_TRANSPARENT | + l10n_util::GetExtendedTooltipStyles()); + popup->set_delete_on_destroy(delete_on_destroy); + return popup; +} + } // namespace views + diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index 9018c64..b15b682 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -71,21 +71,6 @@ class WidgetWin : public Widget, WidgetWin(); virtual ~WidgetWin(); - // Initialize the Widget with a parent and an initial desired size. - // |contents_view| is the view that will be the single child of RootView - // within this Widget. As contents_view is inserted into RootView's tree, - // RootView assumes ownership of this view and cleaning it up. If you remove - // this view, you are responsible for its destruction. If this value is NULL, - // the caller is responsible for populating the RootView, and sizing its - // contents as the window is sized. - void Init(HWND parent, const gfx::Rect& bounds); - - // Sets the specified view as the contents of this Widget. There can only - // be one contnets view child of this Widget's RootView. This view is sized to - // fit the entire size of the RootView. The RootView takes ownership of this - // View, unless it is set as not being parent-owned. - virtual void SetContentsView(View* view); - // Sets the window styles. This is ONLY used when the window is created. // In other words, if you invoke this after invoking Init, nothing happens. void set_window_style(DWORD style) { window_style_ = style; } @@ -211,6 +196,8 @@ class WidgetWin : public Widget, END_MSG_MAP() // Overridden from Widget: + virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); + virtual void SetContentsView(View* view); virtual void GetBounds(gfx::Rect* out, bool including_frame) const; virtual void SetBounds(const gfx::Rect& bounds); virtual void SetShape(const gfx::Path& shape); diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index 076511e..11c2a77 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -7,6 +7,7 @@ #include "app/gfx/path.h" #include "app/l10n_util.h" #include "base/gfx/rect.h" +#include "views/screen.h" #include "views/widget/root_view.h" #include "views/window/custom_frame_view.h" #include "views/window/hit_test.h" @@ -70,19 +71,6 @@ GdkCursorType HitTestCodeToGdkCursorType(int hittest_code) { return GDK_ARROW; } -gfx::Rect GetScreenWorkArea(GdkWindow* window) { - guchar* raw_data = NULL; - gint data_len = 0; - gboolean success = gdk_property_get(gdk_get_default_root_window(), - gdk_atom_intern("_NET_WORKAREA", FALSE), - gdk_atom_intern("CARDINAL", FALSE), - 0, 0xFF, false, NULL, NULL, &data_len, - &raw_data); - DCHECK(success); - glong* data = reinterpret_cast<glong*>(raw_data); - return gfx::Rect(data[0], data[1], data[0] + data[2], data[1] + data[3]); -} - } // namespace namespace views { @@ -442,7 +430,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 = GetScreenWorkArea(GTK_WIDGET(GetNativeWindow())->window); + center_rect = Screen::GetMonitorWorkAreaNearestWindow(GetNativeWindow()); } gfx::Size size = non_client_view_->GetPreferredSize(); gfx::Rect bounds(center_rect.x() + (center_rect.width() - size.width()) / 2, |