Home | History | Annotate | Download | only in caption_buttons
      1 // Copyright 2013 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 ASH_WM_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
      6 #define ASH_WM_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
      7 
      8 #include "ash/ash_export.h"
      9 #include "ash/wm/caption_buttons/alternate_frame_size_button_delegate.h"
     10 #include "ui/gfx/image/image_skia.h"
     11 #include "ui/views/controls/button/button.h"
     12 #include "ui/views/view.h"
     13 
     14 namespace views {
     15 class Widget;
     16 }
     17 
     18 namespace ash {
     19 class FrameCaptionButton;
     20 class FrameMaximizeButton;
     21 
     22 // Container view for the frame caption buttons. It performs the appropriate
     23 // action when a caption button is clicked.
     24 class ASH_EXPORT FrameCaptionButtonContainerView
     25     : public views::View,
     26       public views::ButtonListener,
     27       public AlternateFrameSizeButtonDelegate {
     28  public:
     29   static const char kViewClassName[];
     30 
     31   // Whether the frame can be minimized (either via the maximize/restore button
     32   // or via a dedicated button).
     33   enum MinimizeAllowed {
     34     MINIMIZE_ALLOWED,
     35     MINIMIZE_DISALLOWED
     36   };
     37   enum HeaderStyle {
     38     // Default.
     39     HEADER_STYLE_SHORT,
     40 
     41     // Restored tabbed browser windows.
     42     HEADER_STYLE_TALL
     43   };
     44 
     45   // |frame| is the views::Widget that the caption buttons act on.
     46   // |minimize_allowed| indicates whether the frame can be minimized (either via
     47   // the maximize/restore button or via a dedicated button).
     48   FrameCaptionButtonContainerView(views::Widget* frame,
     49                                   MinimizeAllowed minimize_allowed);
     50   virtual ~FrameCaptionButtonContainerView();
     51 
     52   // For testing.
     53   class TestApi {
     54    public:
     55     explicit TestApi(FrameCaptionButtonContainerView* container_view)
     56         : container_view_(container_view) {
     57     }
     58 
     59     FrameCaptionButton* minimize_button() const {
     60       return container_view_->minimize_button_;
     61     }
     62 
     63     FrameCaptionButton* size_button() const {
     64       return container_view_->size_button_;
     65     }
     66 
     67     FrameCaptionButton* close_button() const {
     68       return container_view_->close_button_;
     69     }
     70 
     71    private:
     72     FrameCaptionButtonContainerView* container_view_;
     73 
     74     DISALLOW_COPY_AND_ASSIGN(TestApi);
     75   };
     76 
     77   // Returns the size button if using the old caption button style, returns NULL
     78   // otherwise.
     79   FrameMaximizeButton* GetOldStyleSizeButton();
     80 
     81   // Tell the window controls to reset themselves to the normal state.
     82   void ResetWindowControls();
     83 
     84   // Determines the window HT* code for the caption button at |point|. Returns
     85   // HTNOWHERE if |point| is not over any of the caption buttons. |point| must
     86   // be in the coordinates of the FrameCaptionButtonContainerView.
     87   int NonClientHitTest(const gfx::Point& point) const;
     88 
     89   // Sets the header style.
     90   void set_header_style(HeaderStyle header_style) {
     91     header_style_ = header_style;
     92   }
     93 
     94   // views::View overrides:
     95   virtual gfx::Size GetPreferredSize() OVERRIDE;
     96   virtual void Layout() OVERRIDE;
     97   virtual const char* GetClassName() const OVERRIDE;
     98   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     99 
    100  private:
    101   friend class FrameCaptionButtonContainerViewTest;
    102 
    103   // views::ButtonListener override:
    104   virtual void ButtonPressed(views::Button* sender,
    105                              const ui::Event& event) OVERRIDE;
    106 
    107   // AlternateFrameSizeButton::Delegate overrides:
    108   virtual bool IsMinimizeButtonVisible() const OVERRIDE;
    109   virtual void SetButtonsToNormal(Animate animate) OVERRIDE;
    110   virtual void SetButtonIcons(CaptionButtonIcon minimize_button_icon,
    111                               CaptionButtonIcon close_button_icon,
    112                               Animate animate) OVERRIDE;
    113   virtual const FrameCaptionButton* PressButtonAt(
    114       const gfx::Point& position_in_screen,
    115       const gfx::Insets& pressed_hittest_outer_insets) const OVERRIDE;
    116 
    117   // The widget that the buttons act on.
    118   views::Widget* frame_;
    119 
    120   // The close button separator.
    121   gfx::ImageSkia button_separator_;
    122 
    123   HeaderStyle header_style_;
    124 
    125   // The buttons. In the normal button style, at most one of |minimize_button_|
    126   // and |size_button_| is visible.
    127   FrameCaptionButton* minimize_button_;
    128   FrameCaptionButton* size_button_;
    129   FrameCaptionButton* close_button_;
    130 
    131   DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView);
    132 };
    133 
    134 }  // namesapace ash
    135 
    136 #endif  // ASH_WM_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_
    137