summaryrefslogtreecommitdiffstats
path: root/chrome/views
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-30 22:30:22 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-30 22:30:22 +0000
commitcb5d17f2f5c9d4a9777439f58e4a7f6eb049e26f (patch)
tree8124412fcae98e1e465668bc66a2f97d9fe7b3a4 /chrome/views
parente3dad87db7cab48a8a1109a49fd1119fd98ff6da (diff)
downloadchromium_src-cb5d17f2f5c9d4a9777439f58e4a7f6eb049e26f.zip
chromium_src-cb5d17f2f5c9d4a9777439f58e4a7f6eb049e26f.tar.gz
chromium_src-cb5d17f2f5c9d4a9777439f58e4a7f6eb049e26f.tar.bz2
Make NonClientView an interface independent of CustomFrameWindow (i.e. move it into its own file).
Rename NonClientView's HitTest method to NonClientHitTest, so it doesn't collide with View's HitTest method. Also, consolidate some duplicated code between CustomFrameWindow and ConstrainedWindow's non-client view impl. B=1300864 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r--chrome/views/custom_frame_window.cc74
-rw-r--r--chrome/views/custom_frame_window.h40
-rw-r--r--chrome/views/non_client_view.cc83
-rw-r--r--chrome/views/non_client_view.h98
-rw-r--r--chrome/views/views.vcproj8
5 files changed, 212 insertions, 91 deletions
diff --git a/chrome/views/custom_frame_window.cc b/chrome/views/custom_frame_window.cc
index a7434aa..8c6bf98 100644
--- a/chrome/views/custom_frame_window.cc
+++ b/chrome/views/custom_frame_window.cc
@@ -41,6 +41,7 @@
#include "chrome/views/button.h"
#include "chrome/views/client_view.h"
#include "chrome/views/native_button.h"
+#include "chrome/views/non_client_view.h"
#include "chrome/views/window_delegate.h"
#include "generated_resources.h"
@@ -229,7 +230,7 @@ ChromeFont InactiveWindowResources::title_font_;
// rendering the non-standard window caption, border, and controls.
//
////////////////////////////////////////////////////////////////////////////////
-class DefaultNonClientView : public CustomFrameWindow::NonClientView,
+class DefaultNonClientView : public NonClientView,
public BaseButton::ButtonListener {
public:
explicit DefaultNonClientView(CustomFrameWindow* container);
@@ -241,7 +242,7 @@ class DefaultNonClientView : public CustomFrameWindow::NonClientView,
virtual gfx::Size CalculateWindowSizeForClientSize(int width,
int height) const;
virtual CPoint GetSystemMenuPoint() const;
- virtual int HitTest(const gfx::Point& point);
+ virtual int NonClientHitTest(const gfx::Point& point);
virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
virtual void EnableClose(bool enable);
@@ -433,7 +434,7 @@ CPoint DefaultNonClientView::GetSystemMenuPoint() const {
// that bound are mirrored if the View uses right-to-left UI layout. This is
// why this function passes APPLY_MIRRORING_TRANSFORMATION as the |settings|
// whenever it calls GetBounds().
-int DefaultNonClientView::HitTest(const gfx::Point& point) {
+int DefaultNonClientView::NonClientHitTest(const gfx::Point& point) {
CRect bounds;
CPoint test_point = point.ToPOINT();
@@ -466,59 +467,20 @@ int DefaultNonClientView::HitTest(const gfx::Point& point) {
if (bounds.PtInRect(test_point))
return HTSYSMENU;
- // Then see if the point is within the resize boundaries.
- int width = GetWidth();
- int height = GetHeight();
- int component = HTNOWHERE;
- if (point.x() < kResizeAreaSize) {
- if (point.y() < kResizeAreaCornerSize) {
- component = HTTOPLEFT;
- } else if (point.y() >= (height - kResizeAreaCornerSize)) {
- component = HTBOTTOMLEFT;
- } else {
- component = HTLEFT;
- }
- } else if (point.x() < kResizeAreaCornerSize) {
- if (point.y() < kResizeAreaNorthSize) {
- component = HTTOPLEFT;
- } else if (point.y() >= (height - kResizeAreaSize)) {
- component = HTBOTTOMLEFT;
- }
- } else if (point.x() >= (width - kResizeAreaSize)) {
- if (point.y() < kResizeAreaCornerSize) {
- component = HTTOPRIGHT;
- } else if (point.y() >= (height - kResizeAreaCornerSize)) {
- component = HTBOTTOMRIGHT;
- } else if (point.x() >= (width - kResizeAreaSize)) {
- component = HTRIGHT;
- }
- } else if (point.x() >= (width - kResizeAreaCornerSize)) {
- if (point.y() < kResizeAreaNorthSize) {
- component = HTTOPRIGHT;
- } else if (point.y() >= (height - kResizeAreaSize)) {
- component = HTBOTTOMRIGHT;
- }
- } else if (point.y() < kResizeAreaNorthSize) {
- component = HTTOP;
- } else if (point.y() >= (height - kResizeAreaSize)) {
- component = HTBOTTOM;
- }
-
- // If the window can't be resized, there are no resize boundaries, just
- // window borders.
- if (component != HTNOWHERE) {
- if (!container_->window_delegate()->CanResize()) {
- return HTBORDER;
- }
- return component;
+ int component = GetHTComponentForFrame(
+ point,
+ kResizeAreaSize,
+ kResizeAreaCornerSize,
+ kResizeAreaNorthSize,
+ container_->window_delegate()->CanResize());
+ if (component == HTNOWHERE) {
+ // Finally fall back to the caption.
+ GetBounds(&bounds, APPLY_MIRRORING_TRANSFORMATION);
+ if (bounds.PtInRect(test_point))
+ component = HTCAPTION;
+ // Otherwise, the point is outside the window's bounds.
}
-
- // Finally fall back to the caption.
- GetBounds(&bounds, APPLY_MIRRORING_TRANSFORMATION);
- if (bounds.PtInRect(test_point))
- return HTCAPTION;
- // The point is outside the window's bounds.
- return HTNOWHERE;
+ return component;
}
void DefaultNonClientView::GetWindowMask(const gfx::Size& size,
@@ -1016,7 +978,7 @@ LRESULT CustomFrameWindow::OnNCHitTest(const CPoint& point) {
// NC points are in screen coordinates.
CPoint temp = point;
MapWindowPoints(HWND_DESKTOP, GetHWND(), &temp, 1);
- return non_client_view_->HitTest(gfx::Point(temp.x, temp.y));
+ return non_client_view_->NonClientHitTest(gfx::Point(temp.x, temp.y));
}
LRESULT CustomFrameWindow::OnNCMouseMove(UINT flags, const CPoint& point) {
diff --git a/chrome/views/custom_frame_window.h b/chrome/views/custom_frame_window.h
index 52356b2..72c7c1c 100644
--- a/chrome/views/custom_frame_window.h
+++ b/chrome/views/custom_frame_window.h
@@ -36,6 +36,8 @@
namespace ChromeViews {
+class NonClientView;
+
////////////////////////////////////////////////////////////////////////////////
//
// CustomFrameWindow
@@ -49,7 +51,6 @@ namespace ChromeViews {
class CustomFrameWindow : public Window {
public:
explicit CustomFrameWindow(WindowDelegate* window_delegate);
- class NonClientView;
CustomFrameWindow(WindowDelegate* window_delegate,
NonClientView* non_client_view);
virtual ~CustomFrameWindow();
@@ -67,38 +68,6 @@ class CustomFrameWindow : public Window {
// Returns whether or not the frame is active.
bool is_active() const { return is_active_; }
- class NonClientView : public View {
- public:
- virtual void Init(ClientView* client_view) = 0;
-
- // 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;
-
- // 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;
-
- // Returns the point, in screen coordinates, where the system menu should
- // be shown so it shows up anchored to the system menu icon.
- virtual CPoint GetSystemMenuPoint() const = 0;
-
- // Determines the windows HT* code when the mouse cursor is at the
- // specified point, in window coordinates.
- virtual int HitTest(const gfx::Point& point) = 0;
-
- // 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;
-
- // Toggles the enable state for the Close button (and the Close menu item in
- // the system menu).
- virtual void EnableClose(bool enable) = 0;
- };
-
// Overridden from Window:
virtual gfx::Size CalculateWindowSizeForClientSize(
const gfx::Size& client_size) const;
@@ -123,11 +92,12 @@ class CustomFrameWindow : public Window {
virtual void OnSize(UINT param, const CSize& size);
// The View that provides the non-client area of the window (title bar,
- // window controls, sizing borders etc).
+ // window controls, sizing borders etc). To use an implementation other than
+ // the default, this class must be subclassed and this value set to the
+ // desired implementation before calling |Init|.
NonClientView* non_client_view_;
private:
-
// Shows the system menu at the specified screen point.
void RunSystemMenu(const CPoint& point);
diff --git a/chrome/views/non_client_view.cc b/chrome/views/non_client_view.cc
new file mode 100644
index 0000000..e04a269
--- /dev/null
+++ b/chrome/views/non_client_view.cc
@@ -0,0 +1,83 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "chrome/views/non_client_view.h"
+
+namespace ChromeViews {
+
+int NonClientView::GetHTComponentForFrame(const gfx::Point& point,
+ int resize_area_size,
+ int resize_area_corner_size,
+ int top_resize_area_size,
+ bool can_resize) {
+ int width = GetWidth();
+ int height = GetHeight();
+ int component = HTNOWHERE;
+ if (point.x() < resize_area_size) {
+ if (point.y() < resize_area_corner_size) {
+ component = HTTOPLEFT;
+ } else if (point.y() >= (height - resize_area_corner_size)) {
+ component = HTBOTTOMLEFT;
+ } else {
+ component = HTLEFT;
+ }
+ } else if (point.x() < resize_area_corner_size) {
+ if (point.y() < top_resize_area_size) {
+ component = HTTOPLEFT;
+ } else if (point.y() >= (height - resize_area_size)) {
+ component = HTBOTTOMLEFT;
+ }
+ } else if (point.x() >= (width - resize_area_size)) {
+ if (point.y() < resize_area_corner_size) {
+ component = HTTOPRIGHT;
+ } else if (point.y() >= (height - resize_area_corner_size)) {
+ component = HTBOTTOMRIGHT;
+ } else if (point.x() >= (width - resize_area_size)) {
+ component = HTRIGHT;
+ }
+ } else if (point.x() >= (width - resize_area_corner_size)) {
+ if (point.y() < top_resize_area_size) {
+ component = HTTOPRIGHT;
+ } else if (point.y() >= (height - resize_area_size)) {
+ component = HTBOTTOMRIGHT;
+ }
+ } else if (point.y() < top_resize_area_size) {
+ component = HTTOP;
+ } else if (point.y() >= (height - resize_area_size)) {
+ component = HTBOTTOM;
+ }
+
+ // If the window can't be resized, there are no resize boundaries, just
+ // window borders.
+ if (component != HTNOWHERE)
+ return can_resize ? component : HTBORDER;
+ return HTNOWHERE;
+}
+
+} // namespace ChromeViews
diff --git a/chrome/views/non_client_view.h b/chrome/views/non_client_view.h
new file mode 100644
index 0000000..f30e956
--- /dev/null
+++ b/chrome/views/non_client_view.h
@@ -0,0 +1,98 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef CHROME_VIEWS_NON_CLIENT_VIEW_H_
+#define CHROME_VIEWS_NON_CLIENT_VIEW_H_
+
+#include "chrome/views/view.h"
+
+namespace gfx {
+class Path;
+}
+
+namespace ChromeViews {
+
+class ClientView;
+
+///////////////////////////////////////////////////////////////////////////////
+// NonClientView
+//
+// An object implementing the NonClientView interface is a View that provides
+// the "non-client" areas of a window. This is the area that typically
+// encompasses the window frame - title bar, sizing borders and window
+// controls. This interface provides methods that allow a specific
+// presentation to define non-client areas for windows hit testing, the shape
+// of the window, and other window-related information.
+//
+class NonClientView : public View {
+ public:
+ virtual void Init(ClientView* client_view) = 0;
+
+ // 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;
+
+ // 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;
+
+ // Returns the point, in screen coordinates, where the system menu should
+ // be shown so it shows up anchored to the system menu icon.
+ virtual CPoint GetSystemMenuPoint() const = 0;
+
+ // 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;
+
+ // 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;
+
+ // Toggles the enable state for the Close button (and the Close menu item in
+ // the system menu).
+ virtual void EnableClose(bool enable) = 0;
+
+ protected:
+ // Helper for non-client view implementations to determine which area of the
+ // window border the specified |point| falls within. The other parameters are
+ // the size of the sizing edges, and whether or not the window can be
+ // resized.
+ int GetHTComponentForFrame(const gfx::Point& point,
+ int resize_area_size,
+ int resize_area_corner_size,
+ int top_resize_area_size,
+ bool can_resize);
+};
+
+} // namespace ChromeViews
+
+#endif // #ifndef CHROME_VIEWS_NON_CLIENT_VIEW_H_
diff --git a/chrome/views/views.vcproj b/chrome/views/views.vcproj
index 0d35a46..928ae37 100644
--- a/chrome/views/views.vcproj
+++ b/chrome/views/views.vcproj
@@ -422,6 +422,14 @@
>
</File>
<File
+ RelativePath=".\non_client_view.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\non_client_view.h"
+ >
+ </File>
+ <File
RelativePath=".\painter.cc"
>
</File>