0

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
This commit is contained in:
ben@chromium.org
2011-03-04 23:31:59 +00:00
parent a40f6e9f49
commit 0b609eee74
7 changed files with 337 additions and 299 deletions

@ -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,

@ -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;

@ -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.

@ -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.";

@ -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,

@ -211,95 +211,10 @@ void WidgetWin::InitWithWidget(Widget* parent, const gfx::Rect& bounds) {
Init(parent->GetNativeView(), bounds);
}
void WidgetWin::SetBounds(const gfx::Rect& bounds) {
LONG style = GetWindowLong(GWL_STYLE);
if (style & WS_MAXIMIZE)
SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE);
SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(),
SWP_NOACTIVATE | SWP_NOZORDER);
}
void WidgetWin::MoveAbove(Widget* other) {
gfx::Rect bounds = GetClientAreaScreenBounds();
SetWindowPos(other->GetNativeView(), bounds.x(), bounds.y(),
bounds.width(), bounds.height(), SWP_NOACTIVATE);
}
void WidgetWin::SetShape(gfx::NativeRegion region) {
SetWindowRgn(region, TRUE);
}
void WidgetWin::Close() {
if (!IsWindow())
return; // No need to do anything.
// Let's hide ourselves right away.
Hide();
if (close_widget_factory_.empty()) {
// And we delay the close so that if we are called from an ATL callback,
// we don't destroy the window before the callback returned (as the caller
// may delete ourselves on destroy and the ATL callback would still
// dereference us when the callback returns).
MessageLoop::current()->PostTask(FROM_HERE,
close_widget_factory_.NewRunnableMethod(
&WidgetWin::CloseNow));
}
}
void WidgetWin::CloseNow() {
// We may already have been destroyed if the selection resulted in a tab
// switch which will have reactivated the browser window and closed us, so
// we need to check to see if we're still a window before trying to destroy
// ourself.
if (IsWindow())
DestroyWindow(hwnd());
}
void WidgetWin::Show() {
if (IsWindow())
ShowWindow(SW_SHOWNOACTIVATE);
}
void WidgetWin::Hide() {
if (IsWindow()) {
// NOTE: Be careful not to activate any windows here (for example, calling
// ShowWindow(SW_HIDE) will automatically activate another window). This
// code can be called while a window is being deactivated, and activating
// another window will screw up the activation that is already in progress.
SetWindowPos(NULL, 0, 0, 0, 0,
SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE |
SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
}
}
gfx::NativeView WidgetWin::GetNativeView() const {
return WindowImpl::hwnd();
}
void WidgetWin::SetOpacity(unsigned char opacity) {
layered_alpha_ = static_cast<BYTE>(opacity);
}
void WidgetWin::SetAlwaysOnTop(bool on_top) {
if (on_top)
set_window_ex_style(window_ex_style() | WS_EX_TOPMOST);
else
set_window_ex_style(window_ex_style() & ~WS_EX_TOPMOST);
}
bool WidgetWin::IsVisible() const {
return !!::IsWindowVisible(hwnd());
}
bool WidgetWin::IsActive() const {
return IsWindowActive(hwnd());
}
bool WidgetWin::IsAccessibleWidget() const {
return screen_reader_active_;
}
void WidgetWin::GenerateMousePressedForView(View* view,
const gfx::Point& point) {
gfx::Point point_in_widget(point);
@ -372,6 +287,90 @@ gfx::Rect WidgetWin::GetClientAreaScreenBounds() const {
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)
SetWindowLong(GWL_STYLE, style & ~WS_MAXIMIZE);
SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(),
SWP_NOACTIVATE | SWP_NOZORDER);
}
void WidgetWin::MoveAbove(Widget* other) {
SetWindowPos(other->GetNativeView(), 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
}
void WidgetWin::SetShape(gfx::NativeRegion region) {
SetWindowRgn(region, TRUE);
}
void WidgetWin::Close() {
if (!IsWindow())
return; // No need to do anything.
// Let's hide ourselves right away.
Hide();
if (close_widget_factory_.empty()) {
// And we delay the close so that if we are called from an ATL callback,
// we don't destroy the window before the callback returned (as the caller
// may delete ourselves on destroy and the ATL callback would still
// dereference us when the callback returns).
MessageLoop::current()->PostTask(FROM_HERE,
close_widget_factory_.NewRunnableMethod(
&WidgetWin::CloseNow));
}
}
void WidgetWin::CloseNow() {
// We may already have been destroyed if the selection resulted in a tab
// switch which will have reactivated the browser window and closed us, so
// we need to check to see if we're still a window before trying to destroy
// ourself.
if (IsWindow())
DestroyWindow(hwnd());
}
void WidgetWin::Show() {
if (IsWindow())
ShowWindow(SW_SHOWNOACTIVATE);
}
void WidgetWin::Hide() {
if (IsWindow()) {
// NOTE: Be careful not to activate any windows here (for example, calling
// ShowWindow(SW_HIDE) will automatically activate another window). This
// code can be called while a window is being deactivated, and activating
// another window will screw up the activation that is already in progress.
SetWindowPos(NULL, 0, 0, 0, 0,
SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE |
SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);
}
}
void WidgetWin::SetOpacity(unsigned char opacity) {
layered_alpha_ = static_cast<BYTE>(opacity);
}
void WidgetWin::SetAlwaysOnTop(bool on_top) {
if (on_top)
set_window_ex_style(window_ex_style() | WS_EX_TOPMOST);
else
set_window_ex_style(window_ex_style() & ~WS_EX_TOPMOST);
}
bool WidgetWin::IsVisible() const {
return !!::IsWindowVisible(hwnd());
}
bool WidgetWin::IsActive() const {
return IsWindowActive(hwnd());
}
bool WidgetWin::IsAccessibleWidget() const {
return screen_reader_active_;
}
bool WidgetWin::ContainsNativeView(gfx::NativeView native_view) const {
if (hwnd() == native_view)
return true;

@ -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,