Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_DEFAULT_HEADER_PAINTER_H_ |
| 6 #define ASH_WM_HEADER_PAINTER_H_ | 6 #define ASH_WM_DEFAULT_HEADER_PAINTER_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "base/basictypes.h" | 9 #include "ash/wm/header_painter.h" |
| 10 #include "base/compiler_specific.h" // OVERRIDE | |
| 11 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "ui/gfx/animation/animation_delegate.h" | 12 #include "ui/gfx/animation/animation_delegate.h" |
| 14 #include "ui/gfx/geometry/rect.h" | |
| 15 | 13 |
| 16 namespace gfx { | 14 namespace gfx { |
| 17 class Canvas; | 15 class Rect; |
| 18 class FontList; | |
| 19 class ImageSkia; | |
| 20 class Point; | |
| 21 class Size; | |
| 22 class SlideAnimation; | 16 class SlideAnimation; |
| 23 } | 17 } |
| 24 namespace views { | 18 namespace views { |
| 25 class View; | 19 class View; |
| 26 class Widget; | 20 class Widget; |
| 27 } | 21 } |
| 28 | 22 |
| 29 namespace ash { | 23 namespace ash { |
| 30 class FrameCaptionButtonContainerView; | 24 class FrameCaptionButtonContainerView; |
| 31 | 25 |
| 32 // Helper class for painting the window header. | 26 class ASH_EXPORT DefaultHeaderPainter : public HeaderPainter, |
|
James Cook
2014/03/10 17:32:30
Needs a class comment.
| |
| 33 class ASH_EXPORT HeaderPainter : public gfx::AnimationDelegate { | 27 public gfx::AnimationDelegate { |
| 34 public: | 28 public: |
| 35 enum Mode { | 29 DefaultHeaderPainter(); |
| 36 MODE_ACTIVE, | 30 virtual ~DefaultHeaderPainter(); |
| 37 MODE_INACTIVE | |
| 38 }; | |
| 39 | 31 |
| 40 // TODO(pkotwicz): Move code related to "browser" windows out of ash. | 32 // DefaultHeaderPainter does not take ownership of any of the parameters. |
| 41 enum Style { | 33 void Init(views::Widget* frame, |
| 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, | 34 views::View* header_view, |
| 56 views::View* window_icon, | 35 views::View* window_icon, |
| 57 FrameCaptionButtonContainerView* caption_button_container); | 36 FrameCaptionButtonContainerView* caption_button_container); |
| 58 | 37 |
| 59 // Returns the bounds of the client view for a window with |header_height| | 38 // HeaderPainter overrides: |
| 60 // and |window_bounds|. The return value and |window_bounds| are in the | 39 virtual int GetMinimumHeaderWidth() const OVERRIDE; |
| 61 // views::NonClientView's coordinates. | 40 virtual void PaintHeader(gfx::Canvas* canvas, Mode mode) OVERRIDE; |
| 62 static gfx::Rect GetBoundsForClientView(int header_height, | 41 virtual void LayoutHeader() OVERRIDE; |
| 63 const gfx::Rect& window_bounds); | 42 virtual int GetHeaderHeightForPainting() const OVERRIDE; |
| 43 virtual void SetHeaderHeightForPainting(int height) OVERRIDE; | |
| 44 virtual void SchedulePaintForTitle() OVERRIDE; | |
| 64 | 45 |
| 65 // Returns the bounds of the window given |header_height| and |client_bounds|. | 46 private: |
| 66 // The return value and |client_bounds| are in the views::NonClientView's | 47 FRIEND_TEST_ALL_PREFIXES(DefaultHeaderPainterTest, TitleIconAlignment); |
| 67 // coordinates. | |
| 68 static gfx::Rect GetWindowBoundsForClientBounds( | |
| 69 int header_height, | |
| 70 const gfx::Rect& client_bounds); | |
| 71 | 48 |
| 72 // Determines the window HT* code at |point|. Returns HTNOWHERE if |point| is | 49 // gfx::AnimationDelegate override: |
| 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 | |
| 79 // Returns the header's minimum width. | |
| 80 int GetMinimumHeaderWidth() const; | |
| 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 | |
| 88 // Paints the header. | |
| 89 // |theme_frame_overlay_id| is 0 if no overlay image should be used. | |
| 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 | |
| 96 // Paints the header/content separator line for non-browser windows. | |
| 97 void PaintHeaderContentSeparator(gfx::Canvas* canvas, Mode mode); | |
| 98 | |
| 99 // Returns size of the header/content separator line for non-browser windows | |
| 100 // in pixels. | |
| 101 int HeaderContentSeparatorSize() const; | |
| 102 | |
| 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 | |
| 120 // Schedule a re-paint of the entire title. | |
| 121 void SchedulePaintForTitle(const gfx::FontList& title_font_list); | |
| 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; | 50 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
| 128 | 51 |
| 129 private: | 52 // Paints a border around the header for inactive restored windows. |
| 130 FRIEND_TEST_ALL_PREFIXES(HeaderPainterTest, TitleIconAlignment); | 53 void PaintBorderForInactiveRestoredWindow(gfx::Canvas* canvas); |
| 131 | 54 |
| 132 // Paints the border around the header. | 55 // Paints the title bar, primarily the title string. |
| 133 void PaintBorder(gfx::Canvas* canvas, Mode mode); | 56 void PaintTitleBar(gfx::Canvas* canvas); |
| 134 | 57 |
| 135 // Updates the images used for the minimize, restore and close buttons. | 58 // Paints the header/content separator. |
| 136 void UpdateCaptionButtonImages(); | 59 void PaintHeaderContentSeparator(gfx::Canvas* canvas); |
| 137 | 60 |
| 138 // Returns the header bounds in the coordinates of |header_view_|. The header | 61 // Returns the header bounds in the coordinates of |view_|. The header is |
| 139 // is assumed to be positioned at the top left corner of |header_view_| and to | 62 // assumed to be positioned at the top left corner of |view_| and to have the |
| 140 // have the same width as |header_view_|. | 63 // same width as |view_|. |
| 141 gfx::Rect GetHeaderLocalBounds() const; | 64 gfx::Rect GetLocalBounds() const; |
| 142 | 65 |
| 143 // Returns the offset between window left edge and title string. | 66 // Returns the bounds for the title. |
| 144 int GetTitleOffsetX() const; | 67 gfx::Rect GetTitleBounds() const; |
| 145 | 68 |
| 146 // Returns the vertical center of the caption button container in window | 69 views::Widget* frame_; |
| 147 // coordinates. | 70 views::View* view_; |
| 148 int GetCaptionButtonContainerCenterY() const; | 71 views::View* window_icon_; |
| 72 FrameCaptionButtonContainerView* caption_button_container_; | |
| 73 int height_; | |
|
James Cook
2014/03/10 17:32:30
nit: Comment which height this is.
| |
| 149 | 74 |
| 150 // Returns the radius of the header's top corners. | 75 // Whether the header should be painted as active. |
| 151 int GetHeaderCornerRadius() const; | 76 Mode mode_; |
| 152 | 77 |
| 153 // Get the bounds for the title. The provided |title_font_list| is used to | 78 // Whether the header is painted for the first time. |
| 154 // determine the correct dimensions. | 79 bool initial_paint_; |
| 155 gfx::Rect GetTitleBounds(const gfx::FontList& title_font_list); | |
| 156 | 80 |
| 157 Style style_; | 81 scoped_ptr<gfx::SlideAnimation> activation_animation_; |
|
James Cook
2014/03/10 17:32:30
Nice, I like this name better.
| |
| 158 | 82 |
| 159 // Not owned | 83 DISALLOW_COPY_AND_ASSIGN(DefaultHeaderPainter); |
| 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 }; | 84 }; |
| 180 | 85 |
| 181 } // namespace ash | 86 } // namespace ash |
| 182 | 87 |
| 183 #endif // ASH_WM_HEADER_PAINTER_H_ | 88 #endif // ASH_WM_DEFAULT_HEADER_PAINTER_H_ |
| OLD | NEW |