Home | History | Annotate | Download | only in window
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_
      6 #define UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_
      7 
      8 #include "ui/views/view.h"
      9 
     10 namespace gfx {
     11 class Path;
     12 }
     13 
     14 namespace views {
     15 
     16 class ClientView;
     17 
     18 ////////////////////////////////////////////////////////////////////////////////
     19 // NonClientFrameView
     20 //
     21 //  An object that subclasses NonClientFrameView is a View that renders and
     22 //  responds to events within the frame portions of the non-client area of a
     23 //  window. This view does _not_ contain the ClientView, but rather is a sibling
     24 //  of it.
     25 class VIEWS_EXPORT NonClientFrameView : public View {
     26  public:
     27   // Internal class name.
     28   static const char kViewClassName[];
     29   // Various edges of the frame border have a 1 px shadow along their edges; in
     30   // a few cases we shift elements based on this amount for visual appeal.
     31   static const int kFrameShadowThickness;
     32   // In restored mode, we draw a 1 px edge around the content area inside the
     33   // frame border.
     34   static const int kClientEdgeThickness;
     35 
     36   // Sets whether the window should be rendered as active regardless of the
     37   // actual active state. Used when bubbles become active to make their parent
     38   // appear active. A value of true makes the window render as active always,
     39   // false gives normal behavior.
     40   void SetInactiveRenderingDisabled(bool disable);
     41 
     42   // Helper for non-client view implementations to determine which area of the
     43   // window border the specified |point| falls within. The other parameters are
     44   // the size of the sizing edges, and whether or not the window can be
     45   // resized.
     46   int GetHTComponentForFrame(const gfx::Point& point,
     47                              int top_resize_border_height,
     48                              int resize_border_thickness,
     49                              int top_resize_corner_height,
     50                              int resize_corner_width,
     51                              bool can_resize);
     52 
     53   // Returns the bounds (in this View's parent's coordinates) that the client
     54   // view should be laid out within.
     55   virtual gfx::Rect GetBoundsForClientView() const = 0;
     56 
     57   virtual gfx::Rect GetWindowBoundsForClientBounds(
     58       const gfx::Rect& client_bounds) const = 0;
     59 
     60   // This function must ask the ClientView to do a hittest.  We don't do this in
     61   // the parent NonClientView because that makes it more difficult to calculate
     62   // hittests for regions that are partially obscured by the ClientView, e.g.
     63   // HTSYSMENU.
     64   virtual int NonClientHitTest(const gfx::Point& point) = 0;
     65   virtual void GetWindowMask(const gfx::Size& size,
     66                              gfx::Path* window_mask) = 0;
     67   virtual void ResetWindowControls() = 0;
     68   virtual void UpdateWindowIcon() = 0;
     69   virtual void UpdateWindowTitle() = 0;
     70 
     71   // Overridden from View:
     72   virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
     73   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
     74   virtual const char* GetClassName() const OVERRIDE;
     75 
     76  protected:
     77   virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
     78 
     79   NonClientFrameView() : paint_as_active_(false) {}
     80 
     81   // Used to determine if the frame should be painted as active. Keyed off the
     82   // window's actual active state and the override, see
     83   // SetInactiveRenderingDisabled() above.
     84   bool ShouldPaintAsActive() const;
     85 
     86   // Invoked from SetInactiveRenderingDisabled(). This implementation invokes
     87   // SchedulesPaint as necessary.
     88   virtual void ShouldPaintAsActiveChanged();
     89 
     90  private:
     91   // True when the non-client view should always be rendered as if the window
     92   // were active, regardless of whether or not the top level window actually
     93   // is active.
     94   bool paint_as_active_;
     95 };
     96 
     97 ////////////////////////////////////////////////////////////////////////////////
     98 // NonClientView
     99 //
    100 //  The NonClientView is the logical root of all Views contained within a
    101 //  Window, except for the RootView which is its parent and of which it is the
    102 //  sole child. The NonClientView has two children, the NonClientFrameView which
    103 //  is responsible for painting and responding to events from the non-client
    104 //  portions of the window, and the ClientView, which is responsible for the
    105 //  same for the client area of the window:
    106 //
    107 //  +- views::Widget ------------------------------------+
    108 //  | +- views::RootView ------------------------------+ |
    109 //  | | +- views::NonClientView ---------------------+ | |
    110 //  | | | +- views::NonClientFrameView subclass ---+ | | |
    111 //  | | | |                                        | | | |
    112 //  | | | | << all painting and event receiving >> | | | |
    113 //  | | | | << of the non-client areas of a     >> | | | |
    114 //  | | | | << views::Widget.                   >> | | | |
    115 //  | | | |                                        | | | |
    116 //  | | | +----------------------------------------+ | | |
    117 //  | | | +- views::ClientView or subclass --------+ | | |
    118 //  | | | |                                        | | | |
    119 //  | | | | << all painting and event receiving >> | | | |
    120 //  | | | | << of the client areas of a         >> | | | |
    121 //  | | | | << views::Widget.                   >> | | | |
    122 //  | | | |                                        | | | |
    123 //  | | | +----------------------------------------+ | | |
    124 //  | | +--------------------------------------------+ | |
    125 //  | +------------------------------------------------+ |
    126 //  +----------------------------------------------------+
    127 //
    128 // The NonClientFrameView and ClientView are siblings because due to theme
    129 // changes the NonClientFrameView may be replaced with different
    130 // implementations (e.g. during the switch from DWM/Aero-Glass to Vista Basic/
    131 // Classic rendering).
    132 //
    133 class VIEWS_EXPORT NonClientView : public View {
    134  public:
    135   // Internal class name.
    136   static const char kViewClassName[];
    137 
    138   NonClientView();
    139   virtual ~NonClientView();
    140 
    141   // Returns the current NonClientFrameView instance, or NULL if
    142   // it does not exist.
    143   NonClientFrameView* frame_view() const { return frame_view_.get(); }
    144 
    145   // Replaces the current NonClientFrameView (if any) with the specified one.
    146   void SetFrameView(NonClientFrameView* frame_view);
    147 
    148   // Replaces the current |overlay_view_| (if any) with the specified one.
    149   void SetOverlayView(View* view);
    150 
    151   // Returns true if the ClientView determines that the containing window can be
    152   // closed, false otherwise.
    153   bool CanClose();
    154 
    155   // Called by the containing Window when it is closed.
    156   void WindowClosing();
    157 
    158   // Replaces the frame view with a new one. Used when switching window theme
    159   // or frame style. Pass true for |layout| to refresh the window layout (the
    160   // common case) or false if you will trigger layout yourself.
    161   void UpdateFrame(bool layout);
    162 
    163   // Prevents the window from being rendered as deactivated when |disable| is
    164   // true, until called with |disable| false. Used when a sub-window is to be
    165   // shown that shouldn't visually de-activate the window.
    166   // Subclasses can override this to perform additional actions when this value
    167   // changes.
    168   void SetInactiveRenderingDisabled(bool disable);
    169 
    170   // Returns the bounds of the window required to display the content area at
    171   // the specified bounds.
    172   gfx::Rect GetWindowBoundsForClientBounds(const gfx::Rect client_bounds) const;
    173 
    174   // Determines the windows HT* code when the mouse cursor is at the
    175   // specified point, in window coordinates.
    176   int NonClientHitTest(const gfx::Point& point);
    177 
    178   // Returns a mask to be used to clip the top level window for the given
    179   // size. This is used to create the non-rectangular window shape.
    180   void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
    181 
    182   // Tells the window controls as rendered by the NonClientView to reset
    183   // themselves to a normal state. This happens in situations where the
    184   // containing window does not receive a normal sequences of messages that
    185   // would lead to the controls returning to this normal state naturally, e.g.
    186   // when the window is maximized, minimized or restored.
    187   void ResetWindowControls();
    188 
    189   // Tells the NonClientView to invalidate the NonClientFrameView's window icon.
    190   void UpdateWindowIcon();
    191 
    192   // Tells the NonClientView to invalidate the NonClientFrameView's window
    193   // title.
    194   void UpdateWindowTitle();
    195 
    196   // Get/Set client_view property.
    197   ClientView* client_view() const { return client_view_; }
    198   void set_client_view(ClientView* client_view) {
    199     client_view_ = client_view;
    200   }
    201 
    202   // Layout just the frame view. This is necessary on Windows when non-client
    203   // metrics such as the position of the window controls changes independently
    204   // of a window resize message.
    205   void LayoutFrameView();
    206 
    207   // Set the accessible name of this view.
    208   void SetAccessibleName(const string16& name);
    209 
    210   // NonClientView, View overrides:
    211   virtual gfx::Size GetPreferredSize() OVERRIDE;
    212   virtual gfx::Size GetMinimumSize() OVERRIDE;
    213   virtual gfx::Size GetMaximumSize() OVERRIDE;
    214   virtual void Layout() OVERRIDE;
    215   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
    216   virtual const char* GetClassName() const OVERRIDE;
    217 
    218   virtual views::View* GetEventHandlerForPoint(
    219       const gfx::Point& point) OVERRIDE;
    220   virtual views::View* GetTooltipHandlerForPoint(
    221       const gfx::Point& point) OVERRIDE;
    222 
    223  protected:
    224   // NonClientView, View overrides:
    225   virtual void ViewHierarchyChanged(
    226       const ViewHierarchyChangedDetails& details) OVERRIDE;
    227 
    228  private:
    229   // A ClientView object or subclass, responsible for sizing the contents view
    230   // of the window, hit testing and perhaps other tasks depending on the
    231   // implementation.
    232   ClientView* client_view_;
    233 
    234   // The NonClientFrameView that renders the non-client portions of the window.
    235   // This object is not owned by the view hierarchy because it can be replaced
    236   // dynamically as the system settings change.
    237   scoped_ptr<NonClientFrameView> frame_view_;
    238 
    239   // The overlay view, when non-NULL and visible, takes up the entire widget and
    240   // is placed on top of the ClientView and NonClientFrameView.
    241   View* overlay_view_;
    242 
    243   // The accessible name of this view.
    244   string16 accessible_name_;
    245 
    246   DISALLOW_COPY_AND_ASSIGN(NonClientView);
    247 };
    248 
    249 }  // namespace views
    250 
    251 #endif  // UI_VIEWS_WINDOW_NON_CLIENT_VIEW_H_
    252