OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_WM_HEADER_PAINTER_H_ | 5 #ifndef ASH_WM_HEADER_PAINTER_H_ |
6 #define ASH_WM_HEADER_PAINTER_H_ | 6 #define ASH_WM_HEADER_PAINTER_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" // OVERRIDE | |
11 #include "base/gtest_prod_util.h" | |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "ui/gfx/animation/animation_delegate.h" | |
14 #include "ui/gfx/geometry/rect.h" | |
15 | 10 |
16 namespace gfx { | 11 namespace gfx { |
17 class Canvas; | 12 class Canvas; |
18 class FontList; | |
19 class ImageSkia; | |
20 class Point; | |
21 class Size; | |
22 class SlideAnimation; | |
23 } | |
24 namespace views { | |
25 class View; | |
26 class Widget; | |
27 } | 13 } |
28 | 14 |
29 namespace ash { | 15 namespace ash { |
30 class FrameCaptionButtonContainerView; | |
31 | 16 |
32 // Helper class for painting the window header. | 17 // Helper class for painting the window header. |
33 class ASH_EXPORT HeaderPainter : public gfx::AnimationDelegate { | 18 class ASH_EXPORT HeaderPainter { |
34 public: | 19 public: |
35 enum Mode { | 20 enum Mode { |
36 MODE_ACTIVE, | 21 MODE_ACTIVE, |
37 MODE_INACTIVE | 22 MODE_INACTIVE |
38 }; | 23 }; |
39 | 24 |
40 // TODO(pkotwicz): Move code related to "browser" windows out of ash. | 25 virtual ~HeaderPainter() { |
41 enum Style { | 26 } |
42 // Header style used for browser windows. | |
43 STYLE_BROWSER, | |
44 | |
45 // Header style used for apps and miscellaneous windows (e.g. task manager). | |
46 STYLE_OTHER | |
47 }; | |
48 | |
49 HeaderPainter(); | |
50 virtual ~HeaderPainter(); | |
51 | |
52 // None of the parameters are owned. | |
53 void Init(Style style, | |
54 views::Widget* frame, | |
55 views::View* header_view, | |
56 views::View* window_icon, | |
57 FrameCaptionButtonContainerView* caption_button_container); | |
58 | |
59 // Returns the bounds of the client view for a window with |header_height| | |
60 // and |window_bounds|. The return value and |window_bounds| are in the | |
61 // views::NonClientView's coordinates. | |
62 static gfx::Rect GetBoundsForClientView(int header_height, | |
63 const gfx::Rect& window_bounds); | |
64 | |
65 // Returns the bounds of the window given |header_height| and |client_bounds|. | |
66 // The return value and |client_bounds| are in the views::NonClientView's | |
67 // coordinates. | |
68 static gfx::Rect GetWindowBoundsForClientBounds( | |
69 int header_height, | |
70 const gfx::Rect& client_bounds); | |
71 | |
72 // Determines the window HT* code at |point|. Returns HTNOWHERE if |point| is | |
73 // not within the top |header_height_| of |header_view_|. |point| is in the | |
74 // coordinates of |header_view_|'s widget. The client view must be hittested | |
75 // before calling this method because a browser's tabs are in the top | |
76 // |header_height_| of |header_view_|. | |
77 int NonClientHitTest(const gfx::Point& point) const; | |
78 | 27 |
79 // Returns the header's minimum width. | 28 // Returns the header's minimum width. |
80 int GetMinimumHeaderWidth() const; | 29 virtual int GetMinimumHeaderWidth() const = 0; |
81 | |
82 // Returns the inset from the right edge. | |
83 int GetRightInset() const; | |
84 | |
85 // Returns the amount that the theme background should be inset. | |
86 int GetThemeBackgroundXInset() const; | |
87 | 30 |
88 // Paints the header. | 31 // Paints the header. |
89 // |theme_frame_overlay_id| is 0 if no overlay image should be used. | 32 virtual void PaintHeader(gfx::Canvas* canvas, Mode mode) = 0; |
90 // |mode| indicates whether the window should be painted as active. | |
91 void PaintHeader(gfx::Canvas* canvas, | |
92 Mode mode, | |
93 int theme_frame_id, | |
94 int theme_frame_overlay_id); | |
95 | 33 |
96 // Paints the header/content separator line for non-browser windows. | 34 // Performs layout for the header. |
97 void PaintHeaderContentSeparator(gfx::Canvas* canvas, Mode mode); | 35 virtual void LayoutHeader() = 0; |
98 | 36 |
99 // Returns size of the header/content separator line for non-browser windows | 37 // Gets / sets how much of the header is painted. This allows the tabstrip to |
100 // in pixels. | 38 // affect the header height. This height does not affect LayoutHeader(). |
101 int HeaderContentSeparatorSize() const; | 39 virtual int GetHeaderHeightForPainting() const = 0; |
102 | 40 virtual void SetHeaderHeightForPainting(int height_for_painting) = 0; |
103 // Paint the title bar, primarily the title string. | |
104 void PaintTitleBar(gfx::Canvas* canvas, const gfx::FontList& title_font_list); | |
105 | |
106 // Performs layout for the header based on |frame_|'s show state. | |
107 void LayoutHeader(); | |
108 | |
109 // Sets the height of the header. The height of the header affects painting, | |
110 // and non client hit tests. It does not affect layout. | |
111 void set_header_height(int header_height) { | |
112 header_height_ = header_height; | |
113 } | |
114 | |
115 // Returns the header height. | |
116 int header_height() const { | |
117 return header_height_; | |
118 } | |
119 | 41 |
120 // Schedule a re-paint of the entire title. | 42 // Schedule a re-paint of the entire title. |
121 void SchedulePaintForTitle(const gfx::FontList& title_font_list); | 43 virtual void SchedulePaintForTitle() = 0; |
122 | |
123 // Called when the browser theme changes. | |
124 void OnThemeChanged(); | |
125 | |
126 // Overridden from gfx::AnimationDelegate | |
127 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; | |
128 | |
129 private: | |
130 FRIEND_TEST_ALL_PREFIXES(HeaderPainterTest, TitleIconAlignment); | |
131 | |
132 // Paints the border around the header. | |
133 void PaintBorder(gfx::Canvas* canvas, Mode mode); | |
134 | |
135 // Updates the images used for the minimize, restore and close buttons. | |
136 void UpdateCaptionButtonImages(); | |
137 | |
138 // Returns the header bounds in the coordinates of |header_view_|. The header | |
139 // is assumed to be positioned at the top left corner of |header_view_| and to | |
140 // have the same width as |header_view_|. | |
141 gfx::Rect GetHeaderLocalBounds() const; | |
142 | |
143 // Returns the offset between window left edge and title string. | |
144 int GetTitleOffsetX() const; | |
145 | |
146 // Returns the vertical center of the caption button container in window | |
147 // coordinates. | |
148 int GetCaptionButtonContainerCenterY() const; | |
149 | |
150 // Returns the radius of the header's top corners. | |
151 int GetHeaderCornerRadius() const; | |
152 | |
153 // Get the bounds for the title. The provided |title_font_list| is used to | |
154 // determine the correct dimensions. | |
155 gfx::Rect GetTitleBounds(const gfx::FontList& title_font_list); | |
156 | |
157 Style style_; | |
158 | |
159 // Not owned | |
160 views::Widget* frame_; | |
161 views::View* header_view_; | |
162 views::View* window_icon_; // May be NULL. | |
163 FrameCaptionButtonContainerView* caption_button_container_; | |
164 | |
165 // The height of the header. | |
166 int header_height_; | |
167 | |
168 // Image ids and opacity last used for painting header. | |
169 int previous_theme_frame_id_; | |
170 int previous_theme_frame_overlay_id_; | |
171 | |
172 // Image ids and opacity we are crossfading from. | |
173 int crossfade_theme_frame_id_; | |
174 int crossfade_theme_frame_overlay_id_; | |
175 | |
176 scoped_ptr<gfx::SlideAnimation> crossfade_animation_; | |
177 | |
178 DISALLOW_COPY_AND_ASSIGN(HeaderPainter); | |
179 }; | 44 }; |
180 | 45 |
181 } // namespace ash | 46 } // namespace ash |
182 | 47 |
183 #endif // ASH_WM_HEADER_PAINTER_H_ | 48 #endif // ASH_WM_HEADER_PAINTER_H_ |
OLD | NEW |