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_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ 6 #define ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ 7 8 #include <map> 9 10 #include "ash/ash_export.h" 11 #include "ash/frame/caption_buttons/frame_size_button_delegate.h" 12 #include "ui/views/controls/button/button.h" 13 #include "ui/views/view.h" 14 15 namespace views { 16 class Widget; 17 } 18 19 namespace ash { 20 21 // Container view for the frame caption buttons. It performs the appropriate 22 // action when a caption button is clicked. 23 class ASH_EXPORT FrameCaptionButtonContainerView 24 : public views::View, 25 public views::ButtonListener, 26 public FrameSizeButtonDelegate { 27 public: 28 static const char kViewClassName[]; 29 30 // Whether the frame can be minimized (either via the maximize/restore button 31 // or via a dedicated button). 32 enum MinimizeAllowed { 33 MINIMIZE_ALLOWED, 34 MINIMIZE_DISALLOWED 35 }; 36 37 // |frame| is the views::Widget that the caption buttons act on. 38 // |minimize_allowed| indicates whether the frame can be minimized (either via 39 // the maximize/restore button or via a dedicated button). 40 FrameCaptionButtonContainerView(views::Widget* frame, 41 MinimizeAllowed minimize_allowed); 42 virtual ~FrameCaptionButtonContainerView(); 43 44 // For testing. 45 class TestApi { 46 public: 47 explicit TestApi(FrameCaptionButtonContainerView* container_view) 48 : container_view_(container_view) { 49 } 50 51 FrameCaptionButton* minimize_button() const { 52 return container_view_->minimize_button_; 53 } 54 55 FrameCaptionButton* size_button() const { 56 return container_view_->size_button_; 57 } 58 59 FrameCaptionButton* close_button() const { 60 return container_view_->close_button_; 61 } 62 63 private: 64 FrameCaptionButtonContainerView* container_view_; 65 66 DISALLOW_COPY_AND_ASSIGN(TestApi); 67 }; 68 69 // Sets the resource ids of the images to paint the button for |icon|. The 70 // FrameCaptionButtonContainerView will keep track of the images to use for 71 // |icon| even if none of the buttons currently use |icon|. 72 void SetButtonImages(CaptionButtonIcon icon, 73 int icon_image_id, 74 int inactive_icon_image_id, 75 int hovered_background_image_id, 76 int pressed_background_image_id); 77 78 // Sets whether the buttons should be painted as active. Does not schedule 79 // a repaint. 80 void SetPaintAsActive(bool paint_as_active); 81 82 // Tell the window controls to reset themselves to the normal state. 83 void ResetWindowControls(); 84 85 // Determines the window HT* code for the caption button at |point|. Returns 86 // HTNOWHERE if |point| is not over any of the caption buttons. |point| must 87 // be in the coordinates of the FrameCaptionButtonContainerView. 88 int NonClientHitTest(const gfx::Point& point) const; 89 90 // Updates the size button's visibility based on whether |frame_| can be 91 // maximized and if maximize mode is enabled. A parent view should relayout 92 // to reflect the change in visibility. 93 void UpdateSizeButtonVisibility(); 94 95 // views::View: 96 virtual gfx::Size GetPreferredSize() const OVERRIDE; 97 virtual void Layout() OVERRIDE; 98 virtual const char* GetClassName() const OVERRIDE; 99 100 private: 101 friend class FrameCaptionButtonContainerViewTest; 102 103 struct ButtonIconIds { 104 ButtonIconIds(); 105 ButtonIconIds(int icon_id, 106 int inactive_icon_id, 107 int hovered_background_id, 108 int pressed_background_id); 109 ~ButtonIconIds(); 110 111 int icon_image_id; 112 int inactive_icon_image_id; 113 int hovered_background_image_id; 114 int pressed_background_image_id; 115 }; 116 117 // Sets |button|'s icon to |icon|. If |animate| is ANIMATE_YES, the button 118 // will crossfade to the new icon. If |animate| is ANIMATE_NO and 119 // |icon| == |button|->icon(), the crossfade animation is progressed to the 120 // end. 121 void SetButtonIcon(FrameCaptionButton* button, 122 CaptionButtonIcon icon, 123 Animate animate); 124 125 // views::ButtonListener: 126 virtual void ButtonPressed(views::Button* sender, 127 const ui::Event& event) OVERRIDE; 128 129 // FrameSizeButtonDelegate: 130 virtual bool IsMinimizeButtonVisible() const OVERRIDE; 131 virtual void SetButtonsToNormal(Animate animate) OVERRIDE; 132 virtual void SetButtonIcons(CaptionButtonIcon minimize_button_icon, 133 CaptionButtonIcon close_button_icon, 134 Animate animate) OVERRIDE; 135 virtual const FrameCaptionButton* GetButtonClosestTo( 136 const gfx::Point& position_in_screen) const OVERRIDE; 137 virtual void SetHoveredAndPressedButtons( 138 const FrameCaptionButton* to_hover, 139 const FrameCaptionButton* to_press) OVERRIDE; 140 141 // The widget that the buttons act on. 142 views::Widget* frame_; 143 144 // The buttons. In the normal button style, at most one of |minimize_button_| 145 // and |size_button_| is visible. 146 FrameCaptionButton* minimize_button_; 147 FrameCaptionButton* size_button_; 148 FrameCaptionButton* close_button_; 149 150 // Mapping of the images needed to paint a button for each of the values of 151 // CaptionButtonIcon. 152 std::map<CaptionButtonIcon, ButtonIconIds> button_icon_id_map_; 153 154 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButtonContainerView); 155 }; 156 157 } // namespace ash 158 159 #endif // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_CONTAINER_VIEW_H_ 160