Don't preload rarely seen large images
[chromium-blink-merge.git] / ash / frame / default_header_painter.h
blob662d4c116ca62806abe32422db47ef163a381394
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.
5 #ifndef ASH_FRAME_DEFAULT_HEADER_PAINTER_H_
6 #define ASH_FRAME_DEFAULT_HEADER_PAINTER_H_
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 "third_party/skia/include/core/SkColor.h"
15 #include "ui/gfx/animation/animation_delegate.h"
17 namespace gfx {
18 class ImageSkia;
19 class Rect;
20 class SlideAnimation;
22 namespace views {
23 class View;
24 class Widget;
27 namespace ash {
28 class FrameCaptionButtonContainerView;
30 // Helper class for painting the default window header.
31 class ASH_EXPORT DefaultHeaderPainter : public HeaderPainter,
32 public gfx::AnimationDelegate {
33 public:
34 DefaultHeaderPainter();
35 ~DefaultHeaderPainter() override;
37 // DefaultHeaderPainter does not take ownership of any of the parameters.
38 void Init(views::Widget* frame,
39 views::View* header_view,
40 FrameCaptionButtonContainerView* caption_button_container);
42 // HeaderPainter overrides:
43 int GetMinimumHeaderWidth() const override;
44 void PaintHeader(gfx::Canvas* canvas, Mode mode) override;
45 void LayoutHeader() override;
46 int GetHeaderHeightForPainting() const override;
47 void SetHeaderHeightForPainting(int height) override;
48 void SchedulePaintForTitle() override;
49 void UpdateLeftViewXInset(int left_view_x_inset) override;
51 // Sets the left header view for the header. Passing NULL removes the view.
52 void UpdateLeftHeaderView(views::View* left_header_view);
54 // Sets the active and inactive frame colors. Note the inactive frame color
55 // will have some transparency added when the frame is drawn.
56 void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color);
58 private:
59 FRIEND_TEST_ALL_PREFIXES(DefaultHeaderPainterTest, TitleIconAlignment);
60 FRIEND_TEST_ALL_PREFIXES(DefaultHeaderPainterTest, LightIcons);
62 // gfx::AnimationDelegate override:
63 void AnimationProgressed(const gfx::Animation* animation) override;
65 // Paints highlight around the edge of the header for inactive restored
66 // windows.
67 void PaintHighlightForInactiveRestoredWindow(gfx::Canvas* canvas);
69 // Paints the title bar, primarily the title string.
70 void PaintTitleBar(gfx::Canvas* canvas);
72 // Paints the header/content separator.
73 void PaintHeaderContentSeparator(gfx::Canvas* canvas);
75 // Layout the left header view.
76 void LayoutLeftHeaderView();
78 // Whether light caption images should be used. This is the case when the
79 // background of the frame is dark.
80 bool ShouldUseLightImages();
82 // Update all the images in the caption buttons.
83 void UpdateAllButtonImages();
85 // Updates the size button's images.
86 void UpdateSizeButtonImages(bool use_light_images);
88 // Returns the header bounds in the coordinates of |view_|. The header is
89 // assumed to be positioned at the top left corner of |view_| and to have the
90 // same width as |view_|.
91 gfx::Rect GetLocalBounds() const;
93 // Returns the bounds for the title.
94 gfx::Rect GetTitleBounds() const;
96 // Returns whether the frame uses custom frame coloring.
97 bool UsesCustomFrameColors() const;
99 views::Widget* frame_;
100 views::View* view_;
101 views::View* left_header_view_; // May be NULL.
102 int left_view_x_inset_;
103 SkColor active_frame_color_;
104 SkColor inactive_frame_color_;
105 FrameCaptionButtonContainerView* caption_button_container_;
107 // The height of the header including the header/content separator.
108 int height_;
110 // Whether the header should be painted as active.
111 Mode mode_;
113 // Whether the header is painted for the first time.
114 bool initial_paint_;
116 scoped_ptr<gfx::SlideAnimation> activation_animation_;
118 DISALLOW_COPY_AND_ASSIGN(DefaultHeaderPainter);
121 } // namespace ash
123 #endif // ASH_FRAME_DEFAULT_HEADER_PAINTER_H_