summaryrefslogtreecommitdiffstats
path: root/chrome/views
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/views')
-rw-r--r--chrome/views/custom_frame_window.cc9
-rw-r--r--chrome/views/custom_frame_window.h1
-rw-r--r--chrome/views/non_client_view.cc71
-rw-r--r--chrome/views/non_client_view.h46
-rw-r--r--chrome/views/window.cc61
-rw-r--r--chrome/views/window.h34
6 files changed, 137 insertions, 85 deletions
diff --git a/chrome/views/custom_frame_window.cc b/chrome/views/custom_frame_window.cc
index d615154..b032b09 100644
--- a/chrome/views/custom_frame_window.cc
+++ b/chrome/views/custom_frame_window.cc
@@ -96,15 +96,6 @@ void CustomFrameWindow::Init(HWND parent, const gfx::Rect& bounds) {
ResetWindowRegion();
}
-void CustomFrameWindow::SetClientView(ClientView* cv) {
- DCHECK(cv && !client_view() && GetHWND());
- set_client_view(cv);
- // For a CustomFrameWindow, the non-client view is the root.
- WidgetWin::SetContentsView(non_client_view_);
- // When the non client view is added to the view hierarchy, it will cause the
- // client view to be added as well.
-}
-
gfx::Size CustomFrameWindow::CalculateWindowSizeForClientSize(
const gfx::Size& client_size) const {
return non_client_view_->CalculateWindowSizeForClientSize(
diff --git a/chrome/views/custom_frame_window.h b/chrome/views/custom_frame_window.h
index 3d16874..ba30881 100644
--- a/chrome/views/custom_frame_window.h
+++ b/chrome/views/custom_frame_window.h
@@ -35,7 +35,6 @@ class CustomFrameWindow : public Window {
// Overridden from Window:
virtual void Init(HWND parent, const gfx::Rect& bounds);
- virtual void SetClientView(ClientView* client_view);
virtual gfx::Size CalculateWindowSizeForClientSize(
const gfx::Size& client_size) const;
virtual void UpdateWindowTitle();
diff --git a/chrome/views/non_client_view.cc b/chrome/views/non_client_view.cc
index 205f0cb..11d4fb0 100644
--- a/chrome/views/non_client_view.cc
+++ b/chrome/views/non_client_view.cc
@@ -3,12 +3,83 @@
// found in the LICENSE file.
#include "chrome/views/non_client_view.h"
+#include "chrome/views/widget.h"
namespace views {
const int NonClientView::kFrameShadowThickness = 1;
const int NonClientView::kClientEdgeThickness = 1;
+////////////////////////////////////////////////////////////////////////////////
+// NonClientView, public:
+
+NonClientView::NonClientView() : paint_as_active_(false) {
+}
+
+NonClientView::~NonClientView() {
+}
+
+bool NonClientView::CanClose() const {
+ return client_view_->CanClose();
+}
+
+void NonClientView::WindowClosing() {
+ client_view_->WindowClosing();
+}
+
+gfx::Rect NonClientView::CalculateClientAreaBounds(int width,
+ int height) const {
+ return gfx::Rect();
+}
+
+gfx::Size NonClientView::CalculateWindowSizeForClientSize(int width,
+ int height) const {
+ return gfx::Size();
+}
+
+gfx::Point NonClientView::GetSystemMenuPoint() const {
+ CPoint temp(0, -kFrameShadowThickness);
+ MapWindowPoints(GetWidget()->GetHWND(), HWND_DESKTOP, &temp, 1);
+ return gfx::Point(temp);
+}
+
+int NonClientView::NonClientHitTest(const gfx::Point& point) {
+ return client_view_->NonClientHitTest(point);
+}
+
+void NonClientView::GetWindowMask(const gfx::Size& size,
+ gfx::Path* window_mask) {
+}
+
+void NonClientView::EnableClose(bool enable) {
+}
+
+void NonClientView::ResetWindowControls() {
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+// NonClientView, View overrides:
+
+gfx::Size NonClientView::GetPreferredSize() {
+ return client_view_->GetPreferredSize();
+}
+
+void NonClientView::Layout() {
+ client_view_->SetBounds(0, 0, width(), height());
+}
+
+void NonClientView::ViewHierarchyChanged(bool is_add, View* parent,
+ View* child) {
+ // Add our Client View as we are added to the Widget so that if we are
+ // subsequently resized all the parent-child relationships are established.
+ if (is_add && GetWidget() && child == this)
+ AddChildView(client_view_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NonClientView, protected:
+
int NonClientView::GetHTComponentForFrame(const gfx::Point& point,
int top_resize_border_height,
int resize_border_thickness,
diff --git a/chrome/views/non_client_view.h b/chrome/views/non_client_view.h
index 2900f98..d4c4a2d 100644
--- a/chrome/views/non_client_view.h
+++ b/chrome/views/non_client_view.h
@@ -6,6 +6,7 @@
#define CHROME_VIEWS_NON_CLIENT_VIEW_H_
#include "chrome/views/view.h"
+#include "chrome/views/client_view.h"
namespace gfx {
class Path;
@@ -13,8 +14,6 @@ class Path;
namespace views {
-class ClientView;
-
///////////////////////////////////////////////////////////////////////////////
// NonClientView
//
@@ -27,6 +26,9 @@ class ClientView;
//
class NonClientView : public View {
public:
+ NonClientView();
+ virtual ~NonClientView();
+
// Various edges of the frame border have a 1 px shadow along their edges; in
// a few cases we shift elements based on this amount for visual appeal.
static const int kFrameShadowThickness;
@@ -34,39 +36,45 @@ class NonClientView : public View {
// frame border.
static const int kClientEdgeThickness;
+ // Returns true if the ClientView determines that the containing window can be
+ // closed, false otherwise.
+ bool CanClose() const;
+
+ // Called by the containing Window when it is closed.
+ void WindowClosing();
+
// Calculates the bounds of the client area of the window assuming the
// window is sized to |width| and |height|.
- virtual gfx::Rect CalculateClientAreaBounds(int width,
- int height) const = 0;
+ virtual gfx::Rect CalculateClientAreaBounds(int width, int height) const;
// Calculates the size of window required to display a client area of the
// specified width and height.
virtual gfx::Size CalculateWindowSizeForClientSize(int width,
- int height) const = 0;
+ int height) const;
// Returns the point, in screen coordinates, where the system menu should
// be shown so it shows up anchored to the system menu icon.
- virtual gfx::Point GetSystemMenuPoint() const = 0;
+ virtual gfx::Point GetSystemMenuPoint() const;
// Determines the windows HT* code when the mouse cursor is at the
// specified point, in window coordinates.
- virtual int NonClientHitTest(const gfx::Point& point) = 0;
+ virtual int NonClientHitTest(const gfx::Point& point);
// Returns a mask to be used to clip the top level window for the given
// size. This is used to create the non-rectangular window shape.
virtual void GetWindowMask(const gfx::Size& size,
- gfx::Path* window_mask) = 0;
+ gfx::Path* window_mask);
// 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);
// Tells the window controls as rendered by the NonClientView to reset
// themselves to a normal state. This happens in situations where the
// containing window does not receive a normal sequences of messages that
// would lead to the controls returning to this normal state naturally, e.g.
// when the window is maximized, minimized or restored.
- virtual void ResetWindowControls() = 0;
+ virtual void ResetWindowControls();
// Prevents the non-client view from rendering as inactive when called with
// |disable| true, until called with false.
@@ -74,8 +82,19 @@ class NonClientView : public View {
paint_as_active_ = paint_as_active;
}
+ // Get/Set client_view property.
+ ClientView* client_view() const { return client_view_; }
+ void set_client_view(ClientView* client_view) {
+ client_view_ = client_view;
+ }
+
+ // NonClientView, View overrides:
+ virtual gfx::Size GetPreferredSize();
+ virtual void Layout();
+
protected:
- NonClientView() : paint_as_active_(false) {}
+ // NonClientView, View overrides:
+ virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
// Helper for non-client view implementations to determine which area of the
// window border the specified |point| falls within. The other parameters are
@@ -92,6 +111,11 @@ class NonClientView : public View {
bool paint_as_active() const { return paint_as_active_; }
private:
+ // A ClientView object or subclass, responsible for sizing the contents view
+ // of the window, hit testing and perhaps other tasks depending on the
+ // implementation.
+ ClientView* client_view_;
+
// True when the non-client view should always be rendered as if the window
// were active, regardless of whether or not the top level window actually
// is active.
diff --git a/chrome/views/window.cc b/chrome/views/window.cc
index 2c3acff..1ad5e80 100644
--- a/chrome/views/window.cc
+++ b/chrome/views/window.cc
@@ -130,7 +130,7 @@ void Window::Close() {
return;
}
- if (client_view_->CanClose()) {
+ if (non_client_view_->CanClose()) {
SaveWindowPosition();
RestoreEnabledIfNecessary();
WidgetWin::Close();
@@ -251,8 +251,7 @@ Window::Window(WindowDelegate* window_delegate)
: WidgetWin(),
focus_on_creation_(true),
window_delegate_(window_delegate),
- non_client_view_(NULL),
- client_view_(NULL),
+ non_client_view_(new NonClientView),
owning_hwnd_(NULL),
minimum_size_(100, 100),
is_modal_(false),
@@ -307,24 +306,8 @@ void Window::Init(HWND parent, const gfx::Rect& bounds) {
}
}
-void Window::SetClientView(ClientView* client_view) {
- DCHECK(client_view && !client_view_ && GetHWND());
- client_view_ = client_view;
- if (non_client_view_) {
- // This will trigger the ClientView to be added by the non-client view.
- WidgetWin::SetContentsView(non_client_view_);
- } else {
- WidgetWin::SetContentsView(client_view_);
- }
-}
-
void Window::SizeWindowToDefault() {
- gfx::Size pref;
- if (non_client_view_) {
- pref = non_client_view_->GetPreferredSize();
- } else {
- pref = client_view_->GetPreferredSize();
- }
+ gfx::Size pref = non_client_view_->GetPreferredSize();
DCHECK(pref.width() > 0 && pref.height() > 0);
// CenterAndSizeWindow adjusts the window size to accommodate the non-client
// area.
@@ -374,10 +357,8 @@ void Window::OnCommand(UINT notification_code, int command_id, HWND window) {
}
void Window::OnDestroy() {
- if (client_view_) {
- client_view_->WindowClosing();
- window_delegate_ = NULL;
- }
+ non_client_view_->WindowClosing();
+ window_delegate_ = NULL;
RestoreEnabledIfNecessary();
WidgetWin::OnDestroy();
}
@@ -396,12 +377,7 @@ LRESULT Window::OnNCHitTest(const CPoint& point) {
// of the non-client area.
CPoint temp = point;
MapWindowPoints(HWND_DESKTOP, GetHWND(), &temp, 1);
- int component = HTNOWHERE;
- if (non_client_view_) {
- component = non_client_view_->NonClientHitTest(gfx::Point(temp));
- } else {
- component = client_view_->NonClientHitTest(gfx::Point(temp));
- }
+ int component = non_client_view_->NonClientHitTest(gfx::Point(temp));
if (component != HTNOWHERE)
return component;
@@ -412,19 +388,10 @@ LRESULT Window::OnNCHitTest(const CPoint& point) {
}
void Window::OnNCLButtonDown(UINT ht_component, const CPoint& point) {
- if (ht_component == HTSYSMENU) {
- gfx::Point system_menu_point;
- if (non_client_view_) {
- system_menu_point = non_client_view_->GetSystemMenuPoint();
- } else {
- CPoint temp(0, -NonClientView::kFrameShadowThickness);
- MapWindowPoints(GetHWND(), HWND_DESKTOP, &temp, 1);
- system_menu_point = gfx::Point(temp);
- }
- RunSystemMenu(system_menu_point);
- } else {
+ if (ht_component == HTSYSMENU)
+ RunSystemMenu(non_client_view_->GetSystemMenuPoint());
+ else
WidgetWin::OnNCLButtonDown(ht_component, point);
- }
}
void Window::OnNCRButtonDown(UINT ht_component, const CPoint& point) {
@@ -479,8 +446,7 @@ void Window::OnSysCommand(UINT notification_code, CPoint click) {
// Now change the actual window's behavior.
AlwaysOnTopChanged();
- } else if ((notification_code == SC_KEYMENU) && (click.x == VK_SPACE) &&
- non_client_view_) {
+ } else if ((notification_code == SC_KEYMENU) && (click.x == VK_SPACE)) {
// Run the system menu at the NonClientView's desired location.
RunSystemMenu(non_client_view_->GetSystemMenuPoint());
} else {
@@ -493,6 +459,13 @@ void Window::OnSysCommand(UINT notification_code, CPoint click) {
////////////////////////////////////////////////////////////////////////////////
// Window, private:
+void Window::SetClientView(ClientView* client_view) {
+ DCHECK(client_view && GetHWND());
+ non_client_view_->set_client_view(client_view);
+ // This will trigger the ClientView to be added by the non-client view.
+ WidgetWin::SetContentsView(non_client_view_);
+}
+
void Window::BecomeModal() {
// We implement modality by crawling up the hierarchy of windows starting
// at the owner, disabling all of them so that they don't receive input
diff --git a/chrome/views/window.h b/chrome/views/window.h
index 38fe2bd..665b4a6 100644
--- a/chrome/views/window.h
+++ b/chrome/views/window.h
@@ -6,6 +6,8 @@
#define CHROME_VIEWS_WINDOW_H__
#include "chrome/common/notification_registrar.h"
+#include "chrome/views/client_view.h"
+#include "chrome/views/non_client_view.h"
#include "chrome/views/widget_win.h"
namespace gfx {
@@ -15,7 +17,6 @@ class Size;
namespace views {
-class ClientView;
class Client;
class NonClientView;
class WindowDelegate;
@@ -91,9 +92,6 @@ class Window : public WidgetWin,
WindowDelegate* window_delegate() const { return window_delegate_; }
- // Returns the ClientView object used by this Window.
- ClientView* client_view() const { return client_view_; }
-
void set_focus_on_creation(bool focus_on_creation) {
focus_on_creation_ = focus_on_creation;
}
@@ -110,6 +108,9 @@ class Window : public WidgetWin,
// The parent of this window.
HWND owning_window() const { return owning_hwnd_; }
+ // Shortcut to access the ClientView associated with this window.
+ ClientView* client_view() const { return non_client_view_->client_view(); }
+
// Returns the preferred size of the contents view of this window based on
// its localized size data. The width in cols is held in a localized string
// resource identified by |col_resource_id|, the height in the same fashion.
@@ -135,15 +136,6 @@ class Window : public WidgetWin,
// centered on screen.
virtual void Init(HWND parent, const gfx::Rect& bounds);
- // Sets the specified view as the ClientView of this Window. The ClientView
- // is responsible for laying out the Window's contents view, as well as
- // performing basic hit-testing, and perhaps other responsibilities depending
- // on the implementation. The Window's view hierarchy takes ownership of the
- // ClientView unless the ClientView specifies otherwise. This must be called
- // only once, and after the native window has been created.
- // This is called by Init. |client_view| cannot be NULL.
- virtual void SetClientView(ClientView* client_view);
-
// Sizes the window to the default size specified by its ClientView.
virtual void SizeWindowToDefault();
@@ -152,8 +144,6 @@ class Window : public WidgetWin,
// to exit.
virtual bool IsAppWindow() const { return false; }
- void set_client_view(ClientView* client_view) { client_view_ = client_view; }
-
// Shows the system menu at the specified screen point.
void RunSystemMenu(const gfx::Point& point);
@@ -183,6 +173,15 @@ class Window : public WidgetWin,
}
private:
+ // Sets the specified view as the ClientView of this Window. The ClientView
+ // is responsible for laying out the Window's contents view, as well as
+ // performing basic hit-testing, and perhaps other responsibilities depending
+ // on the implementation. The Window's view hierarchy takes ownership of the
+ // ClientView unless the ClientView specifies otherwise. This must be called
+ // only once, and after the native window has been created.
+ // This is called by Init. |client_view| cannot be NULL.
+ void SetClientView(ClientView* client_view);
+
// Set the window as modal (by disabling all the other windows).
void BecomeModal();
@@ -219,11 +218,6 @@ class Window : public WidgetWin,
static void InitClass();
static HCURSOR nwse_cursor_;
- // A ClientView object or subclass, responsible for sizing the contents view
- // of the window, hit testing and perhaps other tasks depending on the
- // implementation.
- ClientView* client_view_;
-
// Our window delegate (see Init method for documentation).
WindowDelegate* window_delegate_;