diff options
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/views/constrained_window_impl.cc | 75 | ||||
-rw-r--r-- | chrome/views/custom_frame_window.cc | 74 | ||||
-rw-r--r-- | chrome/views/custom_frame_window.h | 40 | ||||
-rw-r--r-- | chrome/views/non_client_view.cc | 83 | ||||
-rw-r--r-- | chrome/views/non_client_view.h | 98 | ||||
-rw-r--r-- | chrome/views/views.vcproj | 8 |
6 files changed, 229 insertions, 149 deletions
diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc index d61e1dc..f666b50 100644 --- a/chrome/browser/views/constrained_window_impl.cc +++ b/chrome/browser/views/constrained_window_impl.cc @@ -52,6 +52,7 @@ #include "chrome/views/button.h" #include "chrome/views/focus_manager.h" #include "chrome/views/hwnd_view.h" +#include "chrome/views/non_client_view.h" #include "generated_resources.h" #include "net/base/net_util.h" @@ -225,7 +226,7 @@ ChromeFont OTRWindowResources::title_font_; // ConstrainedWindowNonClientView class ConstrainedWindowNonClientView - : public ChromeViews::CustomFrameWindow::NonClientView, + : public ChromeViews::NonClientView, public ChromeViews::BaseButton::ButtonListener, public LocationBarView::Delegate, public Task { @@ -254,13 +255,13 @@ class ConstrainedWindowNonClientView // forces a repaint of the titlebar. void SetShowThrobber(bool show_throbber); - // Overridden from ChromeViews::CustomFrameWindow::NonClientView: + // Overridden from ChromeViews::NonClientView: virtual void Init(ChromeViews::ClientView* client_view); virtual gfx::Rect CalculateClientAreaBounds(int width, int height) const; 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); @@ -537,8 +538,7 @@ void ConstrainedWindowNonClientView::Run() { } //////////////////////////////////////////////////////////////////////////////// -// ConstrainedWindowNonClientView, -// ChromeViews::CustomFrameWindow::NonClientView implementation: +// ConstrainedWindowNonClientView, ChromeViews::NonClientView implementation: void ConstrainedWindowNonClientView::Init( ChromeViews::ClientView* client_view) { @@ -572,7 +572,7 @@ CPoint ConstrainedWindowNonClientView::GetSystemMenuPoint() const { return system_menu_point; } -int ConstrainedWindowNonClientView::HitTest(const gfx::Point& point) { +int ConstrainedWindowNonClientView::NonClientHitTest(const gfx::Point& point) { CRect bounds; CPoint test_point = point.ToPOINT(); @@ -596,59 +596,18 @@ int ConstrainedWindowNonClientView::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 (window_delegate_ && !window_delegate_->CanResize()) { - return HTBORDER; - } - return component; + int component = GetHTComponentForFrame(point, kResizeAreaSize, + kResizeAreaCornerSize, + kResizeAreaNorthSize, + 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); - if (bounds.PtInRect(test_point)) - return HTCAPTION; - // The point is outside the window's bounds. - return HTNOWHERE; + return component; } void ConstrainedWindowNonClientView::GetWindowMask(const gfx::Size& size, 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> |