diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 23:31:59 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 23:31:59 +0000 |
commit | 0b609eee74dc548e3f63aa328b037ca0c1bef2da (patch) | |
tree | 9ec3357ee987a263fc3bd7bbc906cf537b5bc406 | |
parent | a40f6e9f4973f79a1c2682ddac655592fa44884d (diff) | |
download | chromium_src-0b609eee74dc548e3f63aa328b037ca0c1bef2da.zip chromium_src-0b609eee74dc548e3f63aa328b037ca0c1bef2da.tar.gz chromium_src-0b609eee74dc548e3f63aa328b037ca0c1bef2da.tar.bz2 |
Make more methods on Widget non-virtual and move to NativeWidget
BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/6623025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76997 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | views/widget/native_widget.h | 12 | ||||
-rw-r--r-- | views/widget/widget.cc | 87 | ||||
-rw-r--r-- | views/widget/widget.h | 82 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 238 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 24 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 157 | ||||
-rw-r--r-- | views/widget/widget_win.h | 24 |
7 files changed, 331 insertions, 293 deletions
diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h index 8587625..fadad34 100644 --- a/views/widget/native_widget.h +++ b/views/widget/native_widget.h @@ -67,6 +67,18 @@ class NativeWidget { // See method documentation in Widget: virtual gfx::Rect GetWindowScreenBounds() const = 0; virtual gfx::Rect GetClientAreaScreenBounds() const = 0; + virtual void SetBounds(const gfx::Rect& bounds) = 0; + virtual void MoveAbove(Widget* widget) = 0; + virtual void SetShape(gfx::NativeRegion shape) = 0; + virtual void Close() = 0; + virtual void CloseNow() = 0; + virtual void Show() = 0; + virtual void Hide() = 0; + virtual void SetOpacity(unsigned char opacity) = 0; + virtual void SetAlwaysOnTop(bool on_top) = 0; + virtual bool IsVisible() const = 0; + virtual bool IsActive() const = 0; + virtual bool IsAccessibleWidget() const = 0; virtual bool ContainsNativeView(gfx::NativeView native_view) const = 0; virtual void RunShellDrag(View* view, const ui::OSExchangeData& data, diff --git a/views/widget/widget.cc b/views/widget/widget.cc index b805983..c34eb09 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -25,6 +25,8 @@ Widget::Widget() Widget::~Widget() { } +// Unconverted methods (see header) -------------------------------------------- + void Widget::Init(gfx::NativeView parent, const gfx::Rect& bounds) { GetRootView(); default_theme_provider_.reset(new DefaultThemeProvider); @@ -33,6 +35,42 @@ void Widget::Init(gfx::NativeView parent, const gfx::Rect& bounds) { void Widget::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { } +gfx::NativeView Widget::GetNativeView() const { + return NULL; +} + +void Widget::GenerateMousePressedForView(View* view, const gfx::Point& point) { +} + +bool Widget::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { + return false; +} + +Window* Widget::GetWindow() { + return NULL; +} + +const Window* Widget::GetWindow() const { + return NULL; +} + +void Widget::ViewHierarchyChanged(bool is_add, View* parent, View* child) { + if (!is_add) { + if (child == dragged_view_) + dragged_view_ = NULL; + + FocusManager* focus_manager = GetFocusManager(); + if (focus_manager) { + if (focus_manager->GetFocusedView() == child) + focus_manager->SetFocusedView(NULL); + focus_manager->ViewRemoved(parent, child); + } + ViewStorage::GetInstance()->ViewRemoved(parent, child); + } +} + +// Converted methods (see header) ---------------------------------------------- + Widget* Widget::GetTopLevelWidget() { return const_cast<Widget*>( const_cast<const Widget*>(this)->GetTopLevelWidget()); @@ -57,34 +95,39 @@ gfx::Rect Widget::GetClientAreaScreenBounds() const { } void Widget::SetBounds(const gfx::Rect& bounds) { + native_widget_->SetBounds(bounds); } void Widget::MoveAbove(Widget* widget) { + native_widget_->MoveAbove(widget); } void Widget::SetShape(gfx::NativeRegion shape) { + native_widget_->SetShape(shape); } void Widget::Close() { + native_widget_->Close(); } void Widget::CloseNow() { + native_widget_->CloseNow(); } void Widget::Show() { + native_widget_->Show(); } void Widget::Hide() { -} - -gfx::NativeView Widget::GetNativeView() const { - return NULL; + native_widget_->Hide(); } void Widget::SetOpacity(unsigned char opacity) { + native_widget_->SetOpacity(opacity); } void Widget::SetAlwaysOnTop(bool on_top) { + native_widget_->SetAlwaysOnTop(on_top); } RootView* Widget::GetRootView() { @@ -96,30 +139,15 @@ RootView* Widget::GetRootView() { } bool Widget::IsVisible() const { - return false; + return native_widget_->IsVisible(); } bool Widget::IsActive() const { - return false; + return native_widget_->IsActive(); } bool Widget::IsAccessibleWidget() const { - return false; -} - -void Widget::GenerateMousePressedForView(View* view, const gfx::Point& point) { -} - -bool Widget::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { - return false; -} - -Window* Widget::GetWindow() { - return NULL; -} - -const Window* Widget::GetWindow() const { - return NULL; + return native_widget_->IsAccessibleWidget(); } ThemeProvider* Widget::GetThemeProvider() const { @@ -146,21 +174,6 @@ FocusManager* Widget::GetFocusManager() { return focus_manager_.get(); } -void Widget::ViewHierarchyChanged(bool is_add, View* parent, View* child) { - if (!is_add) { - if (child == dragged_view_) - dragged_view_ = NULL; - - FocusManager* focus_manager = GetFocusManager(); - if (focus_manager) { - if (focus_manager->GetFocusedView() == child) - focus_manager->SetFocusedView(NULL); - focus_manager->ViewRemoved(parent, child); - } - ViewStorage::GetInstance()->ViewRemoved(parent, child); - } -} - bool Widget::ContainsNativeView(gfx::NativeView native_view) { if (native_widget_->ContainsNativeView(native_view)) return true; diff --git a/views/widget/widget.h b/views/widget/widget.h index 17b8b1a..2886c04 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -94,6 +94,12 @@ class Widget : public internal::NativeWidgetDelegate, Widget(); + // Unconverted methods ------------------------------------------------------- + + // TODO(beng): + // Widget subclasses are still implementing these methods by overriding from + // here rather than by implementing NativeWidget. + // 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, @@ -104,6 +110,32 @@ class Widget : public internal::NativeWidgetDelegate, virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds); + // Returns the gfx::NativeView associated with this Widget. + virtual gfx::NativeView GetNativeView() const; + + // Starts a drag operation for the specified view. |point| is a position in + // |view| coordinates that the drag was initiated from. + virtual void GenerateMousePressedForView(View* view, + const gfx::Point& point); + + // Returns the accelerator given a command id. Returns false if there is + // no accelerator associated with a given id, which is a common condition. + virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); + + // Returns the Window containing this Widget, or NULL if not contained in a + // window. + virtual Window* GetWindow(); + virtual const Window* GetWindow() const; + + // Forwarded from the RootView so that the widget can do any cleanup. + virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); + + // Converted methods --------------------------------------------------------- + + // TODO(beng): + // Widget subclasses are implementing these methods by implementing + // NativeWidget. Remove this comment once complete. + // Returns the topmost Widget in a hierarchy. Will return NULL if called // before the underlying Native Widget has been initialized. Widget* GetTopLevelWidget(); @@ -128,74 +160,56 @@ class Widget : public internal::NativeWidgetDelegate, gfx::Rect GetClientAreaScreenBounds() const; // Sizes and/or places the widget to the specified bounds, size or position. - virtual void SetBounds(const gfx::Rect& bounds); + void SetBounds(const gfx::Rect& bounds); // Places the widget in front of the specified widget in z-order. - virtual void MoveAbove(Widget* widget); + void MoveAbove(Widget* widget); // Sets a shape on the widget. This takes ownership of shape. - virtual void SetShape(gfx::NativeRegion shape); + void SetShape(gfx::NativeRegion shape); // Hides the widget then closes it after a return to the message loop. - virtual void Close(); + void Close(); + // TODO(beng): Move off public API. // Closes the widget immediately. Compare to |Close|. This will destroy the // window handle associated with this Widget, so should not be called from // any code that expects it to be valid beyond this call. - virtual void CloseNow(); + void CloseNow(); // Shows or hides the widget, without changing activation state. - virtual void Show(); - virtual void Hide(); - - // Returns the gfx::NativeView associated with this Widget. - virtual gfx::NativeView GetNativeView() const; + void Show(); + void Hide(); // Sets the opacity of the widget. This may allow widgets behind the widget // in the Z-order to become visible, depending on the capabilities of the // underlying windowing system. Note that the caller must then schedule a // repaint to allow this change to take effect. - virtual void SetOpacity(unsigned char opacity); + void SetOpacity(unsigned char opacity); // Sets the widget to be on top of all other widgets in the windowing system. - virtual void SetAlwaysOnTop(bool on_top); + void SetAlwaysOnTop(bool on_top); // Returns the RootView contained by this Widget. - virtual RootView* GetRootView(); + RootView* GetRootView(); // Returns whether the Widget is visible to the user. - virtual bool IsVisible() const; + bool IsVisible() const; // Returns whether the Widget is the currently active window. - virtual bool IsActive() const; + bool IsActive() const; // Returns whether the Widget is customized for accessibility. - virtual bool IsAccessibleWidget() const; - - // Starts a drag operation for the specified view. |point| is a position in - // |view| coordinates that the drag was initiated from. - virtual void GenerateMousePressedForView(View* view, - const gfx::Point& point); - - // Returns the accelerator given a command id. Returns false if there is - // no accelerator associated with a given id, which is a common condition. - virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); - - // Returns the Window containing this Widget, or NULL if not contained in a - // window. - virtual Window* GetWindow(); - virtual const Window* GetWindow() const; + bool IsAccessibleWidget() const; // Returns the ThemeProvider that provides theme resources for this Widget. virtual ThemeProvider* GetThemeProvider() const; // Returns the FocusManager for this widget. // Note that all widgets in a widget hierarchy share the same focus manager. + // TODO(beng): remove virtual. virtual FocusManager* GetFocusManager(); - // Forwarded from the RootView so that the widget can do any cleanup. - virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); - // Returns true if the native view |native_view| is contained in the // views::View hierarchy rooted at this widget. // TODO(beng): const. @@ -221,7 +235,7 @@ class Widget : public internal::NativeWidgetDelegate, void SetCursor(gfx::NativeCursor cursor); // Retrieves the focus traversable for this widget. - virtual FocusTraversable* GetFocusTraversable(); + FocusTraversable* GetFocusTraversable(); // Notifies the view hierarchy contained in this widget that theme resources // changed. diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 66be067..faf7406 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -597,129 +597,10 @@ void WidgetGtk::Init(GtkWidget* parent, } } -void WidgetGtk::SetBounds(const gfx::Rect& bounds) { - if (type_ == TYPE_CHILD) { - GtkWidget* parent = gtk_widget_get_parent(widget_); - if (GTK_IS_VIEWS_FIXED(parent)) { - WidgetGtk* parent_widget = static_cast<WidgetGtk*>( - NativeWidget::GetNativeWidgetForNativeView(parent)); - parent_widget->PositionChild(widget_, bounds.x(), bounds.y(), - bounds.width(), bounds.height()); - } else { - DCHECK(GTK_IS_FIXED(parent)) - << "Parent of WidgetGtk has to be Fixed or ViewsFixed"; - // Just request the size if the parent is not WidgetGtk but plain - // GtkFixed. WidgetGtk does not know the minimum size so we assume - // the caller of the SetBounds knows exactly how big it wants to be. - gtk_widget_set_size_request(widget_, bounds.width(), bounds.height()); - if (parent != null_parent_) - gtk_fixed_move(GTK_FIXED(parent), widget_, bounds.x(), bounds.y()); - } - } else { - if (GTK_WIDGET_MAPPED(widget_)) { - // If the widget is mapped (on screen), we can move and resize with one - // call, which avoids two separate window manager steps. - gdk_window_move_resize(widget_->window, bounds.x(), bounds.y(), - bounds.width(), bounds.height()); - } - - // Always call gtk_window_move and gtk_window_resize so that GtkWindow's - // geometry info is up-to-date. - GtkWindow* gtk_window = GTK_WINDOW(widget_); - // TODO: this may need to set an initial size if not showing. - // TODO: need to constrain based on screen size. - if (!bounds.IsEmpty()) { - gtk_window_resize(gtk_window, bounds.width(), bounds.height()); - } - gtk_window_move(gtk_window, bounds.x(), bounds.y()); - } -} - -void WidgetGtk::MoveAbove(Widget* widget) { - DCHECK(widget_); - DCHECK(widget_->window); - // TODO(oshima): gdk_window_restack is not available in gtk2.0, so - // we're simply raising the window to the top. We should switch to - // gdk_window_restack when we upgrade gtk to 2.18 or up. - gdk_window_raise(widget_->window); -} - -void WidgetGtk::SetShape(gfx::NativeRegion region) { - DCHECK(widget_); - DCHECK(widget_->window); - gdk_window_shape_combine_region(widget_->window, region, 0, 0); - gdk_region_destroy(region); -} - -void WidgetGtk::Close() { - if (!widget_) - return; // No need to do anything. - - // Hide first. - Hide(); - if (close_widget_factory_.empty()) { - // And we delay the close just in case we're on the stack. - MessageLoop::current()->PostTask(FROM_HERE, - close_widget_factory_.NewRunnableMethod( - &WidgetGtk::CloseNow)); - } -} - -void WidgetGtk::CloseNow() { - if (widget_) { - gtk_widget_destroy(widget_); // Triggers OnDestroy(). - } -} - -void WidgetGtk::Show() { - if (widget_) { - gtk_widget_show(widget_); - if (widget_->window) - gdk_window_raise(widget_->window); - } -} - -void WidgetGtk::Hide() { - if (widget_) { - gtk_widget_hide(widget_); - if (widget_->window) - gdk_window_lower(widget_->window); - } -} - gfx::NativeView WidgetGtk::GetNativeView() const { return widget_; } -void WidgetGtk::SetOpacity(unsigned char opacity) { - opacity_ = opacity; - if (widget_) { - // We can only set the opacity when the widget has been realized. - gdk_window_set_opacity(widget_->window, static_cast<gdouble>(opacity) / - static_cast<gdouble>(255)); - } -} - -void WidgetGtk::SetAlwaysOnTop(bool on_top) { - DCHECK(type_ != TYPE_CHILD); - always_on_top_ = on_top; - if (widget_) - gtk_window_set_keep_above(GTK_WINDOW(widget_), on_top); -} - -bool WidgetGtk::IsVisible() const { - return GTK_WIDGET_VISIBLE(widget_); -} - -bool WidgetGtk::IsActive() const { - DCHECK(type_ != TYPE_CHILD); - return is_active_; -} - -bool WidgetGtk::IsAccessibleWidget() const { - return false; -} - void WidgetGtk::GenerateMousePressedForView(View* view, const gfx::Point& point) { NOTIMPLEMENTED(); @@ -857,6 +738,125 @@ gfx::Rect WidgetGtk::GetClientAreaScreenBounds() const { return gfx::Rect(x, y, w, h); } +void WidgetGtk::SetBounds(const gfx::Rect& bounds) { + if (type_ == TYPE_CHILD) { + GtkWidget* parent = gtk_widget_get_parent(widget_); + if (GTK_IS_VIEWS_FIXED(parent)) { + WidgetGtk* parent_widget = static_cast<WidgetGtk*>( + NativeWidget::GetNativeWidgetForNativeView(parent)); + parent_widget->PositionChild(widget_, bounds.x(), bounds.y(), + bounds.width(), bounds.height()); + } else { + DCHECK(GTK_IS_FIXED(parent)) + << "Parent of WidgetGtk has to be Fixed or ViewsFixed"; + // Just request the size if the parent is not WidgetGtk but plain + // GtkFixed. WidgetGtk does not know the minimum size so we assume + // the caller of the SetBounds knows exactly how big it wants to be. + gtk_widget_set_size_request(widget_, bounds.width(), bounds.height()); + if (parent != null_parent_) + gtk_fixed_move(GTK_FIXED(parent), widget_, bounds.x(), bounds.y()); + } + } else { + if (GTK_WIDGET_MAPPED(widget_)) { + // If the widget is mapped (on screen), we can move and resize with one + // call, which avoids two separate window manager steps. + gdk_window_move_resize(widget_->window, bounds.x(), bounds.y(), + bounds.width(), bounds.height()); + } + + // Always call gtk_window_move and gtk_window_resize so that GtkWindow's + // geometry info is up-to-date. + GtkWindow* gtk_window = GTK_WINDOW(widget_); + // TODO: this may need to set an initial size if not showing. + // TODO: need to constrain based on screen size. + if (!bounds.IsEmpty()) { + gtk_window_resize(gtk_window, bounds.width(), bounds.height()); + } + gtk_window_move(gtk_window, bounds.x(), bounds.y()); + } +} + +void WidgetGtk::MoveAbove(Widget* widget) { + DCHECK(widget_); + DCHECK(widget_->window); + // TODO(oshima): gdk_window_restack is not available in gtk2.0, so + // we're simply raising the window to the top. We should switch to + // gdk_window_restack when we upgrade gtk to 2.18 or up. + gdk_window_raise(widget_->window); +} + +void WidgetGtk::SetShape(gfx::NativeRegion region) { + DCHECK(widget_); + DCHECK(widget_->window); + gdk_window_shape_combine_region(widget_->window, region, 0, 0); + gdk_region_destroy(region); +} + +void WidgetGtk::Close() { + if (!widget_) + return; // No need to do anything. + + // Hide first. + Hide(); + if (close_widget_factory_.empty()) { + // And we delay the close just in case we're on the stack. + MessageLoop::current()->PostTask(FROM_HERE, + close_widget_factory_.NewRunnableMethod( + &WidgetGtk::CloseNow)); + } +} + +void WidgetGtk::CloseNow() { + if (widget_) { + gtk_widget_destroy(widget_); // Triggers OnDestroy(). + } +} + +void WidgetGtk::Show() { + if (widget_) { + gtk_widget_show(widget_); + if (widget_->window) + gdk_window_raise(widget_->window); + } +} + +void WidgetGtk::Hide() { + if (widget_) { + gtk_widget_hide(widget_); + if (widget_->window) + gdk_window_lower(widget_->window); + } +} + +void WidgetGtk::SetOpacity(unsigned char opacity) { + opacity_ = opacity; + if (widget_) { + // We can only set the opacity when the widget has been realized. + gdk_window_set_opacity(widget_->window, static_cast<gdouble>(opacity) / + static_cast<gdouble>(255)); + } +} + +void WidgetGtk::SetAlwaysOnTop(bool on_top) { + DCHECK(type_ != TYPE_CHILD); + always_on_top_ = on_top; + if (widget_) + gtk_window_set_keep_above(GTK_WINDOW(widget_), on_top); +} + +bool WidgetGtk::IsVisible() const { + return GTK_WIDGET_VISIBLE(widget_); +} + +bool WidgetGtk::IsActive() const { + DCHECK(type_ != TYPE_CHILD); + return is_active_; +} + +bool WidgetGtk::IsAccessibleWidget() const { + return false; +} + bool WidgetGtk::ContainsNativeView(gfx::NativeView native_view) const { // TODO(port) See implementation in WidgetWin::ContainsNativeView. NOTREACHED() << "WidgetGtk::ContainsNativeView is not implemented."; diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index f9b557d..2499bfd 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -152,19 +152,7 @@ class WidgetGtk : public Widget, // Overridden from Widget: virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds); - virtual void SetBounds(const gfx::Rect& bounds); - virtual void MoveAbove(Widget* other); - virtual void SetShape(gfx::NativeRegion region); - virtual void Close(); - virtual void CloseNow(); - virtual void Show(); - virtual void Hide(); virtual gfx::NativeView GetNativeView() const; - virtual void SetOpacity(unsigned char opacity); - virtual void SetAlwaysOnTop(bool on_top); - virtual bool IsVisible() const; - virtual bool IsActive() const; - virtual bool IsAccessibleWidget() const; virtual void GenerateMousePressedForView(View* view, const gfx::Point& point); virtual bool GetAccelerator(int cmd_id, ui::Accelerator* accelerator); @@ -193,6 +181,18 @@ class WidgetGtk : public Widget, virtual TooltipManager* GetTooltipManager() const OVERRIDE; virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE; virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE; + virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; + virtual void MoveAbove(Widget* widget) OVERRIDE; + virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; + virtual void Close() OVERRIDE; + virtual void CloseNow() OVERRIDE; + virtual void Show() OVERRIDE; + virtual void Hide() OVERRIDE; + virtual void SetOpacity(unsigned char opacity) OVERRIDE; + virtual void SetAlwaysOnTop(bool on_top) OVERRIDE; + virtual bool IsVisible() const OVERRIDE; + virtual bool IsActive() const OVERRIDE; + virtual bool IsAccessibleWidget() const OVERRIDE; virtual bool ContainsNativeView(gfx::NativeView native_view) const OVERRIDE; virtual void RunShellDrag(View* view, const ui::OSExchangeData& data, diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 7944e58..26381f1 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -211,6 +211,82 @@ void WidgetWin::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { Init(parent->GetNativeView(), bounds); } +gfx::NativeView WidgetWin::GetNativeView() const { + return WindowImpl::hwnd(); +} + +void WidgetWin::GenerateMousePressedForView(View* view, + const gfx::Point& point) { + gfx::Point point_in_widget(point); + View::ConvertPointToWidget(view, &point_in_widget); + GetRootView()->SetMouseHandler(view); + ProcessMousePressed(point_in_widget.ToPOINT(), MK_LBUTTON, false, false); +} + +bool WidgetWin::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { + return false; +} + +Window* WidgetWin::GetWindow() { + return GetWindowImpl(hwnd()); +} + +const Window* WidgetWin::GetWindow() const { + return GetWindowImpl(hwnd()); +} + +void WidgetWin::ViewHierarchyChanged(bool is_add, View* parent, + View* child) { + Widget::ViewHierarchyChanged(is_add, parent, child); + if (drop_target_.get()) + drop_target_->ResetTargetViewIfEquals(child); + + if (!is_add) + ClearAccessibilityViewEvent(child); +} + +//////////////////////////////////////////////////////////////////////////////// +// WidgetWin, NativeWidget implementation: + +Widget* WidgetWin::GetWidget() { + return this; +} + +void WidgetWin::SetNativeWindowProperty(const char* name, void* value) { + // Remove the existing property (if any). + for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { + if ((*i)->Key() == name) { + props_.erase(i); + break; + } + } + + if (value) + props_.push_back(new ViewProp(hwnd(), name, value)); +} + +void* WidgetWin::GetNativeWindowProperty(const char* name) { + return ViewProp::GetValue(hwnd(), name); +} + +TooltipManager* WidgetWin::GetTooltipManager() const { + return tooltip_manager_.get(); +} + +gfx::Rect WidgetWin::GetWindowScreenBounds() const { + RECT r; + GetWindowRect(&r); + return gfx::Rect(r); +} + +gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { + RECT r; + GetClientRect(&r); + POINT point = { r.left, r.top }; + ClientToScreen(hwnd(), &point); + return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); +} + void WidgetWin::SetBounds(const gfx::Rect& bounds) { LONG style = GetWindowLong(GWL_STYLE); if (style & WS_MAXIMIZE) @@ -220,9 +296,8 @@ void WidgetWin::SetBounds(const gfx::Rect& bounds) { } void WidgetWin::MoveAbove(Widget* other) { - gfx::Rect bounds = GetClientAreaScreenBounds(); - SetWindowPos(other->GetNativeView(), bounds.x(), bounds.y(), - bounds.width(), bounds.height(), SWP_NOACTIVATE); + SetWindowPos(other->GetNativeView(), 0, 0, 0, 0, + SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); } void WidgetWin::SetShape(gfx::NativeRegion region) { @@ -273,10 +348,6 @@ void WidgetWin::Hide() { } } -gfx::NativeView WidgetWin::GetNativeView() const { - return WindowImpl::hwnd(); -} - void WidgetWin::SetOpacity(unsigned char opacity) { layered_alpha_ = static_cast<BYTE>(opacity); } @@ -300,78 +371,6 @@ bool WidgetWin::IsAccessibleWidget() const { return screen_reader_active_; } -void WidgetWin::GenerateMousePressedForView(View* view, - const gfx::Point& point) { - gfx::Point point_in_widget(point); - View::ConvertPointToWidget(view, &point_in_widget); - GetRootView()->SetMouseHandler(view); - ProcessMousePressed(point_in_widget.ToPOINT(), MK_LBUTTON, false, false); -} - -bool WidgetWin::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { - return false; -} - -Window* WidgetWin::GetWindow() { - return GetWindowImpl(hwnd()); -} - -const Window* WidgetWin::GetWindow() const { - return GetWindowImpl(hwnd()); -} - -void WidgetWin::ViewHierarchyChanged(bool is_add, View* parent, - View* child) { - Widget::ViewHierarchyChanged(is_add, parent, child); - if (drop_target_.get()) - drop_target_->ResetTargetViewIfEquals(child); - - if (!is_add) - ClearAccessibilityViewEvent(child); -} - -//////////////////////////////////////////////////////////////////////////////// -// WidgetWin, NativeWidget implementation: - -Widget* WidgetWin::GetWidget() { - return this; -} - -void WidgetWin::SetNativeWindowProperty(const char* name, void* value) { - // Remove the existing property (if any). - for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { - if ((*i)->Key() == name) { - props_.erase(i); - break; - } - } - - if (value) - props_.push_back(new ViewProp(hwnd(), name, value)); -} - -void* WidgetWin::GetNativeWindowProperty(const char* name) { - return ViewProp::GetValue(hwnd(), name); -} - -TooltipManager* WidgetWin::GetTooltipManager() const { - return tooltip_manager_.get(); -} - -gfx::Rect WidgetWin::GetWindowScreenBounds() const { - RECT r; - GetWindowRect(&r); - return gfx::Rect(r); -} - -gfx::Rect WidgetWin::GetClientAreaScreenBounds() const { - RECT r; - GetClientRect(&r); - POINT point = { r.left, r.top }; - ClientToScreen(hwnd(), &point); - return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); -} - bool WidgetWin::ContainsNativeView(gfx::NativeView native_view) const { if (hwnd() == native_view) return true; diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index 6150f4e..e77735b 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -120,19 +120,7 @@ class WidgetWin : public ui::WindowImpl, // Overridden from Widget: virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds) OVERRIDE; virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds) OVERRIDE; - virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; - virtual void MoveAbove(Widget* other) OVERRIDE; - virtual void SetShape(gfx::NativeRegion region) OVERRIDE; - virtual void Close() OVERRIDE; - virtual void CloseNow() OVERRIDE; - virtual void Show() OVERRIDE; - virtual void Hide() OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; - virtual void SetOpacity(unsigned char opacity) OVERRIDE; - virtual void SetAlwaysOnTop(bool on_top) OVERRIDE; - virtual bool IsVisible() const OVERRIDE; - virtual bool IsActive() const OVERRIDE; - virtual bool IsAccessibleWidget() const OVERRIDE; virtual void GenerateMousePressedForView(View* view, const gfx::Point& point) OVERRIDE; virtual bool GetAccelerator(int cmd_id, @@ -218,6 +206,18 @@ class WidgetWin : public ui::WindowImpl, virtual TooltipManager* GetTooltipManager() const OVERRIDE; virtual gfx::Rect GetWindowScreenBounds() const OVERRIDE; virtual gfx::Rect GetClientAreaScreenBounds() const OVERRIDE; + virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE; + virtual void MoveAbove(Widget* widget) OVERRIDE; + virtual void SetShape(gfx::NativeRegion shape) OVERRIDE; + virtual void Close() OVERRIDE; + virtual void CloseNow() OVERRIDE; + virtual void Show() OVERRIDE; + virtual void Hide() OVERRIDE; + virtual void SetOpacity(unsigned char opacity) OVERRIDE; + virtual void SetAlwaysOnTop(bool on_top) OVERRIDE; + virtual bool IsVisible() const OVERRIDE; + virtual bool IsActive() const OVERRIDE; + virtual bool IsAccessibleWidget() const OVERRIDE; virtual bool ContainsNativeView(gfx::NativeView native_view) const OVERRIDE; virtual void RunShellDrag(View* view, const ui::OSExchangeData& data, |