diff options
Diffstat (limited to 'views')
-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 |
11 files changed, 164 insertions, 122 deletions
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, |