diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-05 00:27:45 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-05 00:27:45 +0000 |
commit | 15b708af25ae29933ebafe2133bac0fd1999211a (patch) | |
tree | b7fef8c1dcc491193bfedc8736d66834ae74a059 /views/window | |
parent | be51dd2522544e7906e1cec6ac29ebf765fb2a4b (diff) | |
download | chromium_src-15b708af25ae29933ebafe2133bac0fd1999211a.zip chromium_src-15b708af25ae29933ebafe2133bac0fd1999211a.tar.gz chromium_src-15b708af25ae29933ebafe2133bac0fd1999211a.tar.bz2 |
Make Window class concrete (mostly).
Create NativeWindow/NativeWindowDelegate interfaces.
BUG=72040
TEST=none
TBR=sky
Review URL: http://codereview.chromium.org/6626036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/window')
-rw-r--r-- | views/window/native_window.h | 23 | ||||
-rw-r--r-- | views/window/native_window_delegate.h | 26 | ||||
-rw-r--r-- | views/window/window.cc | 123 | ||||
-rw-r--r-- | views/window/window.h | 102 | ||||
-rw-r--r-- | views/window/window_gtk.cc | 3 | ||||
-rw-r--r-- | views/window/window_gtk.h | 9 | ||||
-rw-r--r-- | views/window/window_win.cc | 3 | ||||
-rw-r--r-- | views/window/window_win.h | 9 |
8 files changed, 258 insertions, 40 deletions
diff --git a/views/window/native_window.h b/views/window/native_window.h new file mode 100644 index 0000000..5347eab --- /dev/null +++ b/views/window/native_window.h @@ -0,0 +1,23 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef VIEWS_WIDGET_NATIVE_WINDOW_H_ +#define VIEWS_WIDGET_NATIVE_WINDOW_H_ +#pragma once + +namespace views { + +//////////////////////////////////////////////////////////////////////////////// +// NativeWindow interface +// +// An interface implemented by an object that encapsulates a native window. +// +class NativeWindow { + public: + virtual ~NativeWindow() {} +}; + +} // namespace views + +#endif // VIEWS_WIDGET_NATIVE_WINDOW_H_ diff --git a/views/window/native_window_delegate.h b/views/window/native_window_delegate.h new file mode 100644 index 0000000..229d588 --- /dev/null +++ b/views/window/native_window_delegate.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef VIEWS_WIDGET_NATIVE_WINDOW_DELEGATE_H_ +#define VIEWS_WIDGET_NATIVE_WINDOW_DELEGATE_H_ +#pragma once + +namespace views { +namespace internal { + +//////////////////////////////////////////////////////////////////////////////// +// NativeWindowDelegate interface +// +// An interface implemented by an object that receives notifications from a +// NativeWindow implementation. +// +class NativeWindowDelegate { + public: + virtual ~NativeWindowDelegate() {} +}; + +} // namespace internal +} // namespace views + +#endif // VIEWS_WIDGET_NATIVE_WINDOW_DELEGATE_H_ diff --git a/views/window/window.cc b/views/window/window.cc index 07380f1..3a14335 100644 --- a/views/window/window.cc +++ b/views/window/window.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,11 +8,21 @@ #include "ui/base/l10n/l10n_font_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/font.h" +#include "ui/gfx/rect.h" #include "ui/gfx/size.h" #include "views/widget/widget.h" namespace views { +//////////////////////////////////////////////////////////////////////////////// +// Window, public: + +Window::Window() : native_window_(NULL) { +} + +Window::~Window() { +} + // static int Window::GetLocalizedContentsWidth(int col_resource_id) { return ui::GetLocalizedContentsWidthForFont(col_resource_id, @@ -49,8 +59,119 @@ void Window::CloseSecondaryWidget(Widget* widget) { } } +gfx::Rect Window::GetBounds() const { + return gfx::Rect(); +} + +gfx::Rect Window::GetNormalBounds() const { + return gfx::Rect(); +} + +void Window::SetWindowBounds(const gfx::Rect& bounds, + gfx::NativeWindow other_window) { +} + +void Window::Show() { +} + +void Window::HideWindow() { +} + +void Window::SetNativeWindowProperty(const char* name, void* value) { +} + +void* Window::GetNativeWindowProperty(const char* name) { + return NULL; +} + +void Window::Activate() { +} + +void Window::Deactivate() { +} + +void Window::Close() { +} + +void Window::Maximize() { +} + +void Window::Minimize() { +} + +void Window::Restore() { +} + +bool Window::IsActive() const { + return false; +} + +bool Window::IsVisible() const { + return false; +} + +bool Window::IsMaximized() const { + return false; +} + +bool Window::IsMinimized() const { + return false; +} + +void Window::SetFullscreen(bool fullscreen) { +} + +bool Window::IsFullscreen() const { + return false; +} + +void Window::SetUseDragFrame(bool use_drag_frame) { +} + bool Window::IsAppWindow() const { return false; } +void Window::EnableClose(bool enable) { +} + +void Window::UpdateWindowTitle() { +} + +void Window::UpdateWindowIcon() { +} + +void Window::SetIsAlwaysOnTop(bool always_on_top) { +} + +NonClientFrameView* Window::CreateFrameViewForWindow() { + return NULL; +} + +void Window::UpdateFrameAfterFrameChange() { +} + +WindowDelegate* Window::GetDelegate() const { + return NULL; +} + +NonClientView* Window::GetNonClientView() const { + return NULL; +} + +ClientView* Window::GetClientView() const { + return NULL; +} + +gfx::NativeWindow Window::GetNativeWindow() const { + return NULL; +} + +bool Window::ShouldUseNativeFrame() const { + return false; +} + +void Window::FrameTypeChanged() { +} + } // namespace views diff --git a/views/window/window.h b/views/window/window.h index 03e4f16..df5a28c 100644 --- a/views/window/window.h +++ b/views/window/window.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #pragma once #include "ui/gfx/native_widget_types.h" +#include "views/window/native_window_delegate.h" namespace gfx { class Font; @@ -17,15 +18,30 @@ class Size; namespace views { class ClientView; +class NativeWindow; class NonClientFrameView; class NonClientView; class Widget; class WindowDelegate; -// An interface implemented by an object that provides a top level window. -class Window { +//////////////////////////////////////////////////////////////////////////////// +// Window class +// +// Encapsulates window-like behavior. See WindowDelegate. +// +// TODO(beng): Subclass Widget as part of V2. +// +// TODO(beng): Note that this class being non-abstract means that we have a +// violation of Google style in that we are using multiple +// inheritance. The intention is to split this into a separate +// object associated with but not equal to a NativeWidget +// implementation. Multiple inheritance is required for this +// transitional step. +// +class Window : public internal::NativeWindowDelegate { public: - virtual ~Window() {} + Window(); + virtual ~Window(); // Creates an instance of an object implementing this interface. // TODO(beng): create a version of this function that takes a NativeView, for @@ -55,33 +71,35 @@ class Window { static void CloseSecondaryWidget(Widget* widget); // Retrieves the window's bounds, including its frame. - virtual gfx::Rect GetBounds() const = 0; + virtual gfx::Rect GetBounds() const; // Retrieves the restored bounds for the window. - virtual gfx::Rect GetNormalBounds() const = 0; + virtual gfx::Rect GetNormalBounds() const; // Sets the Window's bounds. The window is inserted after |other_window| in // the window Z-order. If this window is not yet visible, other_window's // monitor is used as the constraining rectangle, rather than this window's // monitor. virtual void SetWindowBounds(const gfx::Rect& bounds, - gfx::NativeWindow other_window) = 0; + gfx::NativeWindow other_window); // Makes the window visible. - virtual void Show() = 0; + virtual void Show(); // Hides the window. This does not delete the window, it just hides it. This // always hides the window, it is separate from the stack maintained by // Push/PopForceHidden. - virtual void HideWindow() = 0; + virtual void HideWindow(); // Sets/Gets a native window property on the underlying native window object. // Returns NULL if the property does not exist. Setting the property value to // NULL removes the property. - virtual void SetNativeWindowProperty(const char* name, void* value) = 0; - virtual void* GetNativeWindowProperty(const char* name) = 0; + virtual void SetNativeWindowProperty(const char* name, void* value); + virtual void* GetNativeWindowProperty(const char* name); #if defined(OS_WIN) + // TODO(beng): remove these platform-specific methods. + // Hides the window if it hasn't already been force-hidden. The force hidden // count is tracked, so calling multiple times is allowed, you just have to // be sure to call PopForceHidden the same number of times. @@ -100,40 +118,40 @@ class Window { #endif // Activates the window, assuming it already exists and is visible. - virtual void Activate() = 0; + virtual void Activate(); // Deactivates the window, making the next window in the Z order the active // window. - virtual void Deactivate() = 0; + virtual void Deactivate(); // Closes the window, ultimately destroying it. This isn't immediate (it // occurs after a return to the message loop. Implementors must also make sure // that invoking Close multiple times doesn't cause bad things to happen, // since it can happen. - virtual void Close() = 0; + virtual void Close(); // Maximizes/minimizes/restores the window. - virtual void Maximize() = 0; - virtual void Minimize() = 0; - virtual void Restore() = 0; + virtual void Maximize(); + virtual void Minimize(); + virtual void Restore(); // Whether or not the window is currently active. - virtual bool IsActive() const = 0; + virtual bool IsActive() const; // Whether or not the window is currently visible. - virtual bool IsVisible() const = 0; + virtual bool IsVisible() const; // Whether or not the window is maximized or minimized. - virtual bool IsMaximized() const = 0; - virtual bool IsMinimized() const = 0; + virtual bool IsMaximized() const; + virtual bool IsMinimized() const; // Accessors for fullscreen state. - virtual void SetFullscreen(bool fullscreen) = 0; - virtual bool IsFullscreen() const = 0; + virtual void SetFullscreen(bool fullscreen); + virtual bool IsFullscreen() const; // Sets whether or not the window should show its frame as a "transient drag // frame" - slightly transparent and without the standard window controls. - virtual void SetUseDragFrame(bool use_drag_frame) = 0; + virtual void SetUseDragFrame(bool use_drag_frame); // Returns true if the Window is considered to be an "app window" - i.e. // any window which when it is the last of its type closed causes the @@ -142,40 +160,52 @@ class Window { // Toggles the enable state for the Close button (and the Close menu item in // the system menu). - virtual void EnableClose(bool enable) = 0; + virtual void EnableClose(bool enable); // Tell the window to update its title from the delegate. - virtual void UpdateWindowTitle() = 0; + virtual void UpdateWindowTitle(); // Tell the window to update its icon from the delegate. - virtual void UpdateWindowIcon() = 0; + virtual void UpdateWindowIcon(); // Sets whether or not the window is always-on-top. - virtual void SetIsAlwaysOnTop(bool always_on_top) = 0; + virtual void SetIsAlwaysOnTop(bool always_on_top); // Creates an appropriate NonClientFrameView for this window. - virtual NonClientFrameView* CreateFrameViewForWindow() = 0; + virtual NonClientFrameView* CreateFrameViewForWindow(); // Updates the frame after an event caused it to be changed. - virtual void UpdateFrameAfterFrameChange() = 0; + virtual void UpdateFrameAfterFrameChange(); // Retrieves the Window's delegate. - virtual WindowDelegate* GetDelegate() const = 0; + virtual WindowDelegate* GetDelegate() const; // Retrieves the Window's non-client view. - virtual NonClientView* GetNonClientView() const = 0; + virtual NonClientView* GetNonClientView() const; // Retrieves the Window's client view. - virtual ClientView* GetClientView() const = 0; + virtual ClientView* GetClientView() const; // Retrieves the Window's native window handle. - virtual gfx::NativeWindow GetNativeWindow() const = 0; + virtual gfx::NativeWindow GetNativeWindow() const; // Whether we should be using a native frame. - virtual bool ShouldUseNativeFrame() const = 0; + virtual bool ShouldUseNativeFrame() const; // Tell the window that something caused the frame type to change. - virtual void FrameTypeChanged() = 0; + virtual void FrameTypeChanged(); + + protected: + // TODO(beng): Temporarily provided as a way to associate the subclass' + // implementation of NativeWidget with this. + void set_native_window(NativeWindow* native_window) { + native_window_ = native_window; + } + + private: + NativeWindow* native_window_; + + DISALLOW_COPY_AND_ASSIGN(Window); }; } // namespace views diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index 345160e..08c19ed 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -14,6 +14,7 @@ #include "views/widget/root_view.h" #include "views/window/custom_frame_view.h" #include "views/window/hit_test.h" +#include "views/window/native_window_delegate.h" #include "views/window/non_client_view.h" #include "views/window/window_delegate.h" @@ -395,11 +396,13 @@ void WindowGtk::SetInitialFocus() { WindowGtk::WindowGtk(WindowDelegate* window_delegate) : WidgetGtk(TYPE_WINDOW), + ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)), is_modal_(false), window_delegate_(window_delegate), non_client_view_(new NonClientView(this)), window_state_(GDK_WINDOW_STATE_WITHDRAWN), window_closed_(false) { + set_native_window(this); is_window_ = true; DCHECK(!window_delegate_->window_); window_delegate_->window_ = this; diff --git a/views/window/window_gtk.h b/views/window/window_gtk.h index 05edbcc..75a5702 100644 --- a/views/window/window_gtk.h +++ b/views/window/window_gtk.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "views/widget/widget_gtk.h" +#include "views/window/native_window.h" #include "views/window/window.h" namespace gfx { @@ -16,12 +17,15 @@ class Size; }; namespace views { +namespace internal { +class NativeWindowDelegate; +} class Client; class WindowDelegate; // Window implementation for GTK. -class WindowGtk : public WidgetGtk, public Window { +class WindowGtk : public WidgetGtk, public NativeWindow, public Window { public: virtual ~WindowGtk(); @@ -100,6 +104,9 @@ class WindowGtk : public WidgetGtk, public Window { void SetInitialBounds(GtkWindow* parent, const gfx::Rect& bounds); void SizeWindowToDefault(GtkWindow* parent); + // A delegate implementation that handles events received here. + internal::NativeWindowDelegate* delegate_; + // Whether or not the window is modal. This comes from the delegate and is // cached at Init time to avoid calling back to the delegate from the // destructor. diff --git a/views/window/window_win.cc b/views/window/window_win.cc index a7abd23..43bfce5 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -23,6 +23,7 @@ #include "views/widget/root_view.h" #include "views/window/client_view.h" #include "views/window/custom_frame_view.h" +#include "views/window/native_window_delegate.h" #include "views/window/native_frame_view.h" #include "views/window/non_client_view.h" #include "views/window/window_delegate.h" @@ -621,6 +622,7 @@ gfx::Font WindowWin::GetWindowTitleFont() { WindowWin::WindowWin(WindowDelegate* window_delegate) : WidgetWin(), + ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)), focus_on_creation_(true), window_delegate_(window_delegate), non_client_view_(new NonClientView(this)), @@ -640,6 +642,7 @@ WindowWin::WindowWin(WindowDelegate* window_delegate) force_hidden_count_(0), is_right_mouse_pressed_on_caption_(false), last_monitor_(NULL) { + set_native_window(this); is_window_ = true; InitClass(); DCHECK(window_delegate_); diff --git a/views/window/window_win.h b/views/window/window_win.h index 8e5c4dc..aeab57f 100644 --- a/views/window/window_win.h +++ b/views/window/window_win.h @@ -7,6 +7,7 @@ #pragma once #include "views/widget/widget_win.h" +#include "views/window/native_window.h" #include "views/window/window.h" namespace gfx { @@ -16,10 +17,10 @@ class Size; }; namespace views { - namespace internal { -// This is exposed only for testing +class NativeWindowDelegate; +// This is exposed only for testing // Adjusts the value of |child_rect| if necessary to ensure that it is // completely visible within |parent_rect|. void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect, @@ -40,6 +41,7 @@ class WindowDelegate; // /////////////////////////////////////////////////////////////////////////////// class WindowWin : public WidgetWin, + public NativeWindow, public Window { public: virtual ~WindowWin(); @@ -235,6 +237,9 @@ class WindowWin : public WidgetWin, }; static HCURSOR resize_cursors_[6]; + // A delegate implementation that handles events received here. + internal::NativeWindowDelegate* delegate_; + // Our window delegate (see Init method for documentation). WindowDelegate* window_delegate_; |