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 3 // found in the LICENSE file. 4 5 #ifndef ASH_FRAME_DEFAULT_HEADER_PAINTER_H_ 6 #define ASH_FRAME_DEFAULT_HEADER_PAINTER_H_ 7 8 #include "ash/ash_export.h" 9 #include "ash/frame/header_painter.h" 10 #include "base/basictypes.h" 11 #include "base/compiler_specific.h" // OVERRIDE 12 #include "base/gtest_prod_util.h" 13 #include "base/memory/scoped_ptr.h" 14 #include "ui/gfx/animation/animation_delegate.h" 15 16 namespace gfx { 17 class ImageSkia; 18 class Rect; 19 class SlideAnimation; 20 } 21 namespace views { 22 class View; 23 class Widget; 24 } 25 26 namespace ash { 27 class FrameCaptionButtonContainerView; 28 29 // Helper class for painting the default window header. 30 class ASH_EXPORT DefaultHeaderPainter : public HeaderPainter, 31 public gfx::AnimationDelegate { 32 public: 33 DefaultHeaderPainter(); 34 virtual ~DefaultHeaderPainter(); 35 36 // DefaultHeaderPainter does not take ownership of any of the parameters. 37 void Init(views::Widget* frame, 38 views::View* header_view, 39 views::View* window_icon, 40 FrameCaptionButtonContainerView* caption_button_container); 41 42 // HeaderPainter overrides: 43 virtual int GetMinimumHeaderWidth() const OVERRIDE; 44 virtual void PaintHeader(gfx::Canvas* canvas, Mode mode) OVERRIDE; 45 virtual void LayoutHeader() OVERRIDE; 46 virtual int GetHeaderHeightForPainting() const OVERRIDE; 47 virtual void SetHeaderHeightForPainting(int height) OVERRIDE; 48 virtual void SchedulePaintForTitle() OVERRIDE; 49 50 // Sets the window icon for the header. Passing NULL removes the window icon. 51 void UpdateWindowIcon(views::View* window_icon, int icon_size); 52 53 private: 54 FRIEND_TEST_ALL_PREFIXES(DefaultHeaderPainterTest, TitleIconAlignment); 55 56 // gfx::AnimationDelegate override: 57 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; 58 59 // Paints highlight around the edge of the header for inactive restored 60 // windows. 61 void PaintHighlightForInactiveRestoredWindow(gfx::Canvas* canvas); 62 63 // Paints the title bar, primarily the title string. 64 void PaintTitleBar(gfx::Canvas* canvas); 65 66 // Paints the header/content separator. 67 void PaintHeaderContentSeparator(gfx::Canvas* canvas); 68 69 // Returns the header bounds in the coordinates of |view_|. The header is 70 // assumed to be positioned at the top left corner of |view_| and to have the 71 // same width as |view_|. 72 gfx::Rect GetLocalBounds() const; 73 74 // Returns the bounds for the title. 75 gfx::Rect GetTitleBounds() const; 76 77 // Returns the frame image to use when |frame_| is active. 78 gfx::ImageSkia* GetActiveFrameImage() const; 79 80 // Returns the frame image to use when |frame_| is inactive. 81 gfx::ImageSkia* GetInactiveFrameImage() const; 82 83 views::Widget* frame_; 84 views::View* view_; 85 views::View* window_icon_; // May be NULL. 86 int window_icon_size_; 87 FrameCaptionButtonContainerView* caption_button_container_; 88 89 // The height of the header including the header/content separator. 90 int height_; 91 92 // Whether the header should be painted as active. 93 Mode mode_; 94 95 // Whether the header is painted for the first time. 96 bool initial_paint_; 97 98 scoped_ptr<gfx::SlideAnimation> activation_animation_; 99 100 DISALLOW_COPY_AND_ASSIGN(DefaultHeaderPainter); 101 }; 102 103 } // namespace ash 104 105 #endif // ASH_FRAME_DEFAULT_HEADER_PAINTER_H_ 106