diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 17:01:46 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 17:01:46 +0000 |
commit | 9756ba445d7c6c7be8b9c885e944ccbf21742b3f (patch) | |
tree | 96bd517c4df7a0f05c38531ac5b96838ab132b30 /views/window/window.cc | |
parent | 6c572a070755401823bb0f84d36913dbe1032334 (diff) | |
download | chromium_src-9756ba445d7c6c7be8b9c885e944ccbf21742b3f.zip chromium_src-9756ba445d7c6c7be8b9c885e944ccbf21742b3f.tar.gz chromium_src-9756ba445d7c6c7be8b9c885e944ccbf21742b3f.tar.bz2 |
Revert 85269 - Split the hierarchy.
* Widget ----
Now recognizes a supplied NativeWidget via InitParams. If this is specified then a default one is not created.
Is now created directly rather than using a factory. NativeWidget creation is not performed until Init() is called. This means some functions that rely on a NativeWidget must not be called until _AFTER_ Init() (explains some of the function call reordering in this CL, e.g. moving SetOpacity() until after Init()).
ResetLastMouseMovedFlag() moved to this API so that BaseTabStrip can call it in a cross-platform way.
Made last remaining unimplemented methods on Widget pass-thru to NativeWidget implementations.
* WidgetWin/WidgetGtk ----
The NativeWidget implementations now both require a NativeWidgetDelegate implementation upon construction. This is passed through the constructor by the static factory method NativeWidget::CreateNativeWidget and by subclasses such as WindowWin, BubbleWidgetWin, etc.
Some classes that are constructed directly (e.g. LockWindow, in ChromeOS) never have a Widget created for them, so they create the Widget themselves in their base class initializer.
Code in these classes (and their WindowWin/WindowGtk, BrowserFrameWin, BrowserFrameGtk subclasses) must now call GetWidget() etc to call Widget API methods since they are no longer subclasses.
static_casting to this (and derived) types must now be done on the Widget's native_widget().
GetWindow() is renamed to GetContainingWindow() to avoid naming conflicts.
* Window ----
Window is now a subclass of Widget.
Now recognizes a supplied NativeWindow via InitParams. If this is specified then a default one is not created.
Window::CloseWindow becomes an override of Widget::Close.
CloseAllSecondaryWindows() becomes CloseAllSecondaryWidgets() and moves to widget.h
IsAppWindow() is removed and replaced by set_is_secondary_widget on Widget.
* MenuHost ----
Subclasses Widget now.
* TabContentsViewViews ----
It looks like the Gtk-views code here was still using the old implementation of the Native version of this class - i.e. a class that subclassed TabContentsView AND WidgetGtk. A no-no. I had to write NativeTabContentsViewGtk, which is almost identical to NativeTabContentsViewWin with the Gtk bits of TabContentsViewGtk thrown in.
* BrowserFrame ----
Platform-specific functionality is now restricted to BrowserFrameWin/BrowserFrameGtk behind a NativeBrowserFrame interface. Construction is exposed via a static factory method on NativeBrowserFrame.
BrowserFrame becomes a concrete class that now subclasses Window.
As a result, it no longer needs a GetWindow() accessor method, so people with a BrowserFrame* can just call Window methods directly on it.
It is constructed directly, replacing the BrowserFrame::Create() method.
NativeBrowserFrameDelegate is no longer needed.
BrowserFrameChromeos is simpler as a couple of #ifdefs in BrowserFrame, so I got rid of that too.
* AutocompletePopupWin/Gtk ----
No longer required. AutocompletePopupContentsView now just uses a Widget directly.
* There is some lingering ugliness:
- If you set a native_window field on Window::InitParams you must also manually set widget_init_params.native_widget. I will make InitParams do more of this automatically later.
- It'd be nice for the ContentsView to be specified via InitParams. I'll get to this later.
- NativeBrowserFrame could probably disappear as an interface. It only exists to provide a couple of methods that may be implemented in other ways.
- delete_on_destroy should now be an ownership directionality enum. I will do this later.
- Secondary-widgetness should somehow be inferred from transience. Later.
- set_focus_on_creation for both the NativeWidgets should probably move to Widget if it is really needed.
- WidgetWin/Gtk::SetInitialFocus seems like it could move to Widget.
- I need to clean up function order in some cases.
BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/7012006
TBR=ben@chromium.org
Review URL: http://codereview.chromium.org/7011038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85283 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/window/window.cc')
-rw-r--r-- | views/window/window.cc | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/views/window/window.cc b/views/window/window.cc index efc9f15..13f2515 100644 --- a/views/window/window.cc +++ b/views/window/window.cc @@ -47,7 +47,7 @@ Window::~Window() { Window* Window::CreateChromeWindow(gfx::NativeWindow parent, const gfx::Rect& bounds, WindowDelegate* window_delegate) { - Window* window = new Window; + Window* window = NativeWindow::CreateNativeWindow(); Window::InitParams params(window_delegate); params.parent_window = parent; params.widget_init_params.bounds = bounds; @@ -74,24 +74,34 @@ gfx::Size Window::GetLocalizedContentsSize(int col_resource_id, GetLocalizedContentsHeight(row_resource_id)); } +// static +void Window::CloseSecondaryWidget(Widget* widget) { + if (!widget) + return; + + // Close widget if it's identified as a secondary window. + Window* window = widget->GetWindow(); + if (window) { + if (!window->IsAppWindow()) + window->CloseWindow(); + } else { + // If it's not a Window, then close it anyway since it probably is + // secondary. + widget->Close(); + } +} + void Window::InitWindow(const InitParams& params) { window_delegate_ = params.window_delegate; AsWidget()->set_widget_delegate(window_delegate_); DCHECK(window_delegate_); DCHECK(!window_delegate_->window_); window_delegate_->window_ = this; - set_widget_delegate(window_delegate_); - native_window_ = - params.native_window ? params.native_window - : NativeWindow::CreateNativeWindow(this); // If frame_view was set already, don't replace it with default one. if (!non_client_view()->frame_view()) non_client_view()->SetFrameView(CreateFrameViewForWindow()); - InitParams modified_params = params; - modified_params.widget_init_params.native_widget = - native_window_->AsNativeWidget(); - Init(modified_params.widget_init_params); - OnNativeWindowCreated(modified_params.widget_init_params.bounds); + AsWidget()->Init(params.widget_init_params); + OnNativeWindowCreated(params.widget_init_params.bounds); } gfx::Rect Window::GetBounds() const { @@ -139,7 +149,7 @@ void Window::Deactivate() { native_window_->Deactivate(); } -void Window::Close() { +void Window::CloseWindow() { if (window_closed_) { // It appears we can hit this code path if you close a modal dialog then // close the last browser before the destructor is hit, which triggers @@ -149,7 +159,9 @@ void Window::Close() { if (non_client_view_->CanClose()) { SaveWindowPosition(); - Widget::Close(); + // TODO(beng): This can be simplified to Widget::Close() once Window + // subclasses Widget. + native_window_->AsNativeWidget()->GetWidget()->Close(); window_closed_ = true; } } @@ -194,6 +206,10 @@ void Window::SetUseDragFrame(bool use_drag_frame) { native_window_->SetUseDragFrame(use_drag_frame); } +bool Window::IsAppWindow() const { + return native_window_->IsAppWindow(); +} + void Window::EnableClose(bool enable) { non_client_view_->EnableClose(enable); native_window_->EnableClose(enable); @@ -245,6 +261,21 @@ void Window::FrameTypeChanged() { native_window_->FrameTypeChanged(); } +Widget* Window::AsWidget() { + return const_cast<Widget*>(const_cast<const Window*>(this)->AsWidget()); +} + +const Widget* Window::AsWidget() const { + return native_window_->AsNativeWidget()->GetWidget(); +} + +//////////////////////////////////////////////////////////////////////////////// +// Window, protected: + +void Window::SetNativeWindow(NativeWindow* native_window) { + native_window_ = native_window; +} + //////////////////////////////////////////////////////////////////////////////// // Window, internal::NativeWindowDelegate implementation: @@ -333,14 +364,6 @@ void Window::OnNativeWindowBoundsChanged() { SaveWindowPosition(); } -Window* Window::AsWindow() { - return this; -} - -internal::NativeWidgetDelegate* Window::AsNativeWidgetDelegate() { - return this; -} - //////////////////////////////////////////////////////////////////////////////// // Window, private: |