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 CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_HEADER_PAINTER_ASH_H_ |
| 6 #define ASH_WM_HEADER_PAINTER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_HEADER_PAINTER_ASH_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/wm/header_painter.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" | 9 #include "base/memory/scoped_ptr.h" |
| 13 #include "ui/gfx/animation/animation_delegate.h" | 10 #include "ui/gfx/animation/animation_delegate.h" |
| 14 #include "ui/gfx/geometry/rect.h" | 11 |
| 12 class BrowserView; | |
| 13 | |
| 14 namespace ash { | |
| 15 class FrameCaptionButtonContainerView; | |
| 16 } | |
| 15 | 17 |
| 16 namespace gfx { | 18 namespace gfx { |
| 17 class Canvas; | |
| 18 class FontList; | |
| 19 class ImageSkia; | 19 class ImageSkia; |
| 20 class Point; | 20 class Rect; |
| 21 class Size; | |
| 22 class SlideAnimation; | 21 class SlideAnimation; |
| 23 } | 22 } |
| 24 namespace views { | 23 namespace views { |
| 25 class View; | 24 class View; |
| 26 class Widget; | 25 class Widget; |
| 27 } | 26 } |
| 28 | 27 |
| 29 namespace ash { | 28 class BrowserHeaderPainterAsh : public ash::HeaderPainter, |
|
James Cook
2014/03/10 17:32:30
Class comment please
| |
| 30 class FrameCaptionButtonContainerView; | 29 public gfx::AnimationDelegate { |
| 30 public: | |
| 31 BrowserHeaderPainterAsh(); | |
| 32 virtual ~BrowserHeaderPainterAsh(); | |
| 31 | 33 |
| 32 // Helper class for painting the window header. | 34 // BrowserHeaderPainterAsh does not take ownership of any of the parameters. |
| 33 class ASH_EXPORT HeaderPainter : public gfx::AnimationDelegate { | 35 void Init( |
| 34 public: | 36 views::Widget* frame, |
| 35 enum Mode { | 37 BrowserView* browser_view, |
| 36 MODE_ACTIVE, | 38 views::View* header_view, |
| 37 MODE_INACTIVE | 39 views::View* window_icon, |
| 38 }; | 40 ash::FrameCaptionButtonContainerView* caption_button_container); |
| 39 | 41 |
| 40 // TODO(pkotwicz): Move code related to "browser" windows out of ash. | 42 // ash::HeaderPainter overrides: |
| 41 enum Style { | 43 virtual int GetMinimumHeaderWidth() const OVERRIDE; |
| 42 // Header style used for browser windows. | 44 virtual void PaintHeader(gfx::Canvas* canvas, Mode mode) OVERRIDE; |
| 43 STYLE_BROWSER, | 45 virtual void LayoutHeader() OVERRIDE; |
| 46 virtual int GetHeaderHeightForPainting() const OVERRIDE; | |
| 47 virtual void SetHeaderHeightForPainting(int height) OVERRIDE; | |
| 48 virtual void SchedulePaintForTitle() OVERRIDE; | |
| 44 | 49 |
| 45 // Header style used for apps and miscellaneous windows (e.g. task manager). | 50 private: |
| 46 STYLE_OTHER | 51 // gfx::AnimationDelegate override: |
| 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 | |
| 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; | 52 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
| 128 | 53 |
| 129 private: | 54 // Paints a border around the header for restored windows. |
| 130 FRIEND_TEST_ALL_PREFIXES(HeaderPainterTest, TitleIconAlignment); | 55 void PaintBorderForRestoredWindow(gfx::Canvas* canvas); |
| 131 | 56 |
| 132 // Paints the border around the header. | 57 // Paints the title bar, primarily the title string. |
| 133 void PaintBorder(gfx::Canvas* canvas, Mode mode); | 58 void PaintTitleBar(gfx::Canvas* canvas); |
| 59 | |
| 60 // Sets |frame_image| and |frame_overlay_image| to the frame image and the | |
| 61 // frame overlay image respectivately which should be used to paint the | |
| 62 // header. | |
| 63 void GetFrameImages(Mode mode, | |
| 64 gfx::ImageSkia* frame_image, | |
| 65 gfx::ImageSkia* frame_overlay_image) const; | |
| 66 | |
| 67 // Sets |frame_image| and |frame_overlay_image| to the frame image and the | |
| 68 // frame overlay image respectively that should be used to paint the header | |
| 69 // for tabbed browser windows. | |
| 70 void GetFrameImagesForTabbedBrowser( | |
| 71 Mode mode, | |
| 72 gfx::ImageSkia* frame_image, | |
| 73 gfx::ImageSkia* frame_overlay_image) const; | |
| 74 | |
| 75 // Returns the frame image which should be used to paint the header for popup | |
| 76 // browser windows and for hosted apps when the toolbar is visible. | |
| 77 gfx::ImageSkia GetFrameImageForNonTabbedBrowser(Mode mode) const; | |
| 134 | 78 |
| 135 // Updates the images used for the minimize, restore and close buttons. | 79 // Updates the images used for the minimize, restore and close buttons. |
| 136 void UpdateCaptionButtonImages(); | 80 void UpdateCaptionButtonImages(); |
| 137 | 81 |
| 138 // Returns the header bounds in the coordinates of |header_view_|. The header | 82 // Returns bounds of the region in |view_| which is painted with the header |
| 139 // is assumed to be positioned at the top left corner of |header_view_| and to | 83 // images. The region is assumed to start at the top left corner of |
| 140 // have the same width as |header_view_|. | 84 // |view_| and to have the same width as |view_|. |
| 141 gfx::Rect GetHeaderLocalBounds() const; | 85 gfx::Rect GetPaintedBounds() const; |
| 142 | 86 |
| 143 // Returns the offset between window left edge and title string. | 87 // Returns the bounds for the title. |
| 144 int GetTitleOffsetX() const; | 88 gfx::Rect GetTitleBounds() const; |
| 145 | 89 |
| 146 // Returns the vertical center of the caption button container in window | 90 views::Widget* frame_; |
| 147 // coordinates. | |
| 148 int GetCaptionButtonContainerCenterY() const; | |
| 149 | 91 |
| 150 // Returns the radius of the header's top corners. | 92 // Whether the header is for a tabbed browser window. |
| 151 int GetHeaderCornerRadius() const; | 93 bool is_tabbed_; |
| 152 | 94 |
| 153 // Get the bounds for the title. The provided |title_font_list| is used to | 95 // Whether the header is for an incognito browser window. |
| 154 // determine the correct dimensions. | 96 bool is_incognito_; |
| 155 gfx::Rect GetTitleBounds(const gfx::FontList& title_font_list); | |
| 156 | 97 |
| 157 Style style_; | 98 // The header view. |
| 99 views::View* view_; | |
| 158 | 100 |
| 159 // Not owned | 101 views::View* window_icon_; |
| 160 views::Widget* frame_; | 102 ash::FrameCaptionButtonContainerView* caption_button_container_; |
| 161 views::View* header_view_; | 103 int painted_height_; |
| 162 views::View* window_icon_; // May be NULL. | |
| 163 FrameCaptionButtonContainerView* caption_button_container_; | |
| 164 | 104 |
| 165 // The height of the header. | 105 // Whether the header is painted for the first time. |
| 166 int header_height_; | 106 bool initial_paint_; |
| 167 | 107 |
| 168 // Image ids and opacity last used for painting header. | 108 // Whether the header should be painted as active. |
| 169 int previous_theme_frame_id_; | 109 Mode mode_; |
| 170 int previous_theme_frame_overlay_id_; | |
| 171 | 110 |
| 172 // Image ids and opacity we are crossfading from. | 111 scoped_ptr<gfx::SlideAnimation> activation_animation_; |
| 173 int crossfade_theme_frame_id_; | |
| 174 int crossfade_theme_frame_overlay_id_; | |
| 175 | 112 |
| 176 scoped_ptr<gfx::SlideAnimation> crossfade_animation_; | 113 DISALLOW_COPY_AND_ASSIGN(BrowserHeaderPainterAsh); |
| 177 | |
| 178 DISALLOW_COPY_AND_ASSIGN(HeaderPainter); | |
| 179 }; | 114 }; |
| 180 | 115 |
| 181 } // namespace ash | 116 #endif // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_HEADER_PAINTER_ASH_H_ |
| 182 | |
| 183 #endif // ASH_WM_HEADER_PAINTER_H_ | |
| OLD | NEW |