Let shift globally trigger slow animation mode.
[chromium-blink-merge.git] / ash / wm / custom_frame_view_ash.cc
blobb94cfcce57e45acd2627bb83c38ab711a00c92a6
1 // Copyright (c) 2012 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 #include "ash/wm/custom_frame_view_ash.h"
7 #include "ash/wm/frame_painter.h"
8 #include "ash/wm/workspace/frame_maximize_button.h"
9 #include "grit/ash_resources.h"
10 #include "grit/ui_strings.h" // Accessibility names
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/compositor/layer_animator.h"
14 #include "ui/gfx/font.h"
15 #include "ui/gfx/image/image.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/size.h"
18 #include "ui/views/controls/button/image_button.h"
19 #include "ui/views/widget/native_widget_aura.h"
20 #include "ui/views/widget/widget.h"
21 #include "ui/views/widget/widget_delegate.h"
23 namespace {
25 const gfx::Font& GetTitleFont() {
26 static gfx::Font* title_font = NULL;
27 if (!title_font)
28 title_font = new gfx::Font(views::NativeWidgetAura::GetWindowTitleFont());
29 return *title_font;
32 } // namespace
34 namespace ash {
36 // static
37 const char CustomFrameViewAsh::kViewClassName[] = "ash/wm/CustomFrameViewAsh";
39 ////////////////////////////////////////////////////////////////////////////////
40 // CustomFrameViewAsh, public:
41 CustomFrameViewAsh::CustomFrameViewAsh()
42 : frame_(NULL),
43 maximize_button_(NULL),
44 close_button_(NULL),
45 window_icon_(NULL),
46 frame_painter_(new ash::FramePainter) {
49 CustomFrameViewAsh::~CustomFrameViewAsh() {
52 void CustomFrameViewAsh::Init(views::Widget* frame) {
53 frame_ = frame;
55 maximize_button_ = new FrameMaximizeButton(this, this);
56 maximize_button_->SetAccessibleName(
57 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_MAXIMIZE));
58 AddChildView(maximize_button_);
59 close_button_ = new views::ImageButton(this);
60 close_button_->SetAccessibleName(
61 l10n_util::GetStringUTF16(IDS_APP_ACCNAME_CLOSE));
62 AddChildView(close_button_);
64 maximize_button_->SetVisible(frame_->widget_delegate()->CanMaximize());
66 if (frame_->widget_delegate()->ShouldShowWindowIcon()) {
67 window_icon_ = new views::ImageButton(this);
68 AddChildView(window_icon_);
71 frame_painter_->Init(frame_, window_icon_, maximize_button_, close_button_,
72 FramePainter::SIZE_BUTTON_MAXIMIZES);
75 ////////////////////////////////////////////////////////////////////////////////
76 // CustomFrameViewAsh, views::NonClientFrameView overrides:
77 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const {
78 int top_height = NonClientTopBorderHeight();
79 return frame_painter_->GetBoundsForClientView(top_height,
80 bounds());
83 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds(
84 const gfx::Rect& client_bounds) const {
85 int top_height = NonClientTopBorderHeight();
86 return frame_painter_->GetWindowBoundsForClientBounds(top_height,
87 client_bounds);
90 int CustomFrameViewAsh::NonClientHitTest(const gfx::Point& point) {
91 return frame_painter_->NonClientHitTest(this, point);
94 void CustomFrameViewAsh::GetWindowMask(const gfx::Size& size,
95 gfx::Path* window_mask) {
96 // No window masks in Aura.
99 void CustomFrameViewAsh::ResetWindowControls() {
100 maximize_button_->SetState(views::CustomButton::STATE_NORMAL);
103 void CustomFrameViewAsh::UpdateWindowIcon() {
104 if (window_icon_)
105 window_icon_->SchedulePaint();
108 void CustomFrameViewAsh::UpdateWindowTitle() {
109 frame_painter_->SchedulePaintForTitle(this, GetTitleFont());
112 ////////////////////////////////////////////////////////////////////////////////
113 // CustomFrameViewAsh, views::View overrides:
115 gfx::Size CustomFrameViewAsh::GetPreferredSize() {
116 gfx::Size pref = frame_->client_view()->GetPreferredSize();
117 gfx::Rect bounds(0, 0, pref.width(), pref.height());
118 return frame_->non_client_view()->GetWindowBoundsForClientBounds(
119 bounds).size();
122 void CustomFrameViewAsh::Layout() {
123 // Use the shorter maximized layout headers.
124 frame_painter_->LayoutHeader(this, true);
127 void CustomFrameViewAsh::OnPaint(gfx::Canvas* canvas) {
128 if (frame_->IsFullscreen())
129 return;
131 bool paint_as_active = ShouldPaintAsActive();
132 int theme_image_id = paint_as_active ? IDR_AURA_WINDOW_HEADER_BASE_ACTIVE :
133 IDR_AURA_WINDOW_HEADER_BASE_INACTIVE;
134 frame_painter_->PaintHeader(
135 this,
136 canvas,
137 paint_as_active ? FramePainter::ACTIVE : FramePainter::INACTIVE,
138 theme_image_id,
139 NULL);
140 frame_painter_->PaintTitleBar(this, canvas, GetTitleFont());
141 frame_painter_->PaintHeaderContentSeparator(this, canvas);
144 std::string CustomFrameViewAsh::GetClassName() const {
145 return kViewClassName;
148 gfx::Size CustomFrameViewAsh::GetMinimumSize() {
149 return frame_painter_->GetMinimumSize(this);
152 ////////////////////////////////////////////////////////////////////////////////
153 // views::ButtonListener overrides:
154 void CustomFrameViewAsh::ButtonPressed(views::Button* sender,
155 const ui::Event& event) {
156 if (sender == maximize_button_) {
157 // The maximize button may move out from under the cursor.
158 ResetWindowControls();
159 if (frame_->IsMaximized())
160 frame_->Restore();
161 else
162 frame_->Maximize();
163 // |this| may be deleted - some windows delete their frames on maximize.
164 } else if (sender == close_button_) {
165 frame_->Close();
169 ////////////////////////////////////////////////////////////////////////////////
170 // CustomFrameViewAsh, private:
172 int CustomFrameViewAsh::NonClientTopBorderHeight() const {
173 if (frame_->IsFullscreen())
174 return 0;
176 // Reserve enough space to see the buttons, including any offset from top and
177 // reserving space for the separator line.
178 return close_button_->bounds().bottom() +
179 frame_painter_->HeaderContentSeparatorSize();
182 } // namespace ash