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 "third_party/skia/include/core/SkColor.h"
15#include "ui/gfx/animation/animation_delegate.h"
16
17namespace gfx {
18class ImageSkia;
19class Rect;
20class SlideAnimation;
21}
22namespace views {
23class View;
24class Widget;
25}
26
27namespace ash {
28class FrameCaptionButtonContainerView;
29
30// Helper class for painting the default window header.
31class ASH_EXPORT DefaultHeaderPainter : public HeaderPainter,
32                                        public gfx::AnimationDelegate {
33 public:
34  DefaultHeaderPainter();
35  virtual ~DefaultHeaderPainter();
36
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);
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  virtual void UpdateLeftViewXInset(int left_view_x_inset) OVERRIDE;
50
51  // Sets the left header view for the header. Passing NULL removes the view.
52  void UpdateLeftHeaderView(views::View* left_header_view);
53
54 private:
55  FRIEND_TEST_ALL_PREFIXES(DefaultHeaderPainterTest, TitleIconAlignment);
56
57  // gfx::AnimationDelegate override:
58  virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
59
60  // Paints highlight around the edge of the header for inactive restored
61  // windows.
62  void PaintHighlightForInactiveRestoredWindow(gfx::Canvas* canvas);
63
64  // Paints the title bar, primarily the title string.
65  void PaintTitleBar(gfx::Canvas* canvas);
66
67  // Paints the header/content separator.
68  void PaintHeaderContentSeparator(gfx::Canvas* canvas);
69
70  // Layout the left header view.
71  void LayoutLeftHeaderView();
72
73  // Updates the size button's images.
74  void UpdateSizeButtonImages();
75
76  // Returns the header bounds in the coordinates of |view_|. The header is
77  // assumed to be positioned at the top left corner of |view_| and to have the
78  // same width as |view_|.
79  gfx::Rect GetLocalBounds() const;
80
81  // Returns the bounds for the title.
82  gfx::Rect GetTitleBounds() const;
83
84  // Returns the frame color to use when |frame_| is inactive.
85  SkColor GetInactiveFrameColor() const;
86
87  views::Widget* frame_;
88  views::View* view_;
89  views::View* left_header_view_;  // May be NULL.
90  int left_view_x_inset_;
91  FrameCaptionButtonContainerView* caption_button_container_;
92
93  // The height of the header including the header/content separator.
94  int height_;
95
96  // Whether the header should be painted as active.
97  Mode mode_;
98
99  // Whether the header is painted for the first time.
100  bool initial_paint_;
101
102  scoped_ptr<gfx::SlideAnimation> activation_animation_;
103
104  DISALLOW_COPY_AND_ASSIGN(DefaultHeaderPainter);
105};
106
107}  // namespace ash
108
109#endif  // ASH_FRAME_DEFAULT_HEADER_PAINTER_H_
110