Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: chrome/browser/ui/views/frame/app_non_client_frame_view_aura.cc

Issue 9359022: Aura: Support hovering restore & close buttons for full screen apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser_test Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/views/frame/app_non_client_frame_view_aura.h"
6
7 #include "base/debug/stack_trace.h"
8 #include "chrome/browser/ui/views/frame/browser_frame.h"
9 #include "chrome/browser/ui/views/frame/browser_view.h"
10 #include "grit/ui_resources.h"
11 #include "ui/aura/window.h"
12 #include "ui/base/animation/slide_animation.h"
13 #include "ui/base/hit_test.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/compositor/layer.h"
17 #include "ui/gfx/compositor/scoped_layer_animation_settings.h"
18 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/point.h"
20 #include "ui/gfx/rect.h"
21 #include "ui/gfx/size.h"
22 #include "ui/views/controls/button/image_button.h"
23 #include "ui/views/widget/widget.h"
24 #include "ui/views/window/non_client_view.h"
25
26 namespace {
27 // The number of pixels to use as a hover zone at the top of the screen.
28 const int kTopMargin = 1;
29 // How long the hover animation takes if uninterrupted.
30 const int kHoverFadeDurationMs = 130;
31 // The number of pixels within the shadow to draw the buttons.
32 const int kShadowStart = 28;
33 }
34
35 class AppNonClientFrameViewAura::ControlView
36 : public views::View, public views::ButtonListener {
37 public:
38 explicit ControlView(AppNonClientFrameViewAura* owner) :
39 owner_(owner),
40 close_button_(CreateImageButton(IDR_AURA_WINDOW_FULLSCREEN_CLOSE)),
41 restore_button_(CreateImageButton(IDR_AURA_WINDOW_FULLSCREEN_RESTORE)) {
42 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
43 separator_ =
44 *rb.GetImageNamed(IDR_AURA_WINDOW_FULLSCREEN_SEPARATOR).ToSkBitmap();
45 shadow_ = *rb.GetImageNamed(IDR_AURA_WINDOW_FULLSCREEN_SHADOW).ToSkBitmap();
46 AddChildView(close_button_);
47 AddChildView(restore_button_);
48 }
49
50 virtual void Layout() OVERRIDE {
51 restore_button_->SetPosition(gfx::Point(kShadowStart, 0));
52 close_button_->SetPosition(
53 gfx::Point(kShadowStart + close_button_->width() + separator_.width(),
54 0));
55 }
56
57 virtual gfx::Size GetPreferredSize() OVERRIDE {
58 return gfx::Size(shadow_.width(), shadow_.height());
59 }
60
61 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
62 views::View::OnPaint(canvas);
63 canvas->DrawBitmapInt(
64 separator_, restore_button_->x() + restore_button_->width(), 0);
65 canvas->DrawBitmapInt(shadow_, 0, 0);
66 }
67
68 void ButtonPressed(
69 views::Button* sender,
70 const views::Event& event) OVERRIDE {
71 if (sender == close_button_)
72 owner_->Close();
73 else if (sender == restore_button_)
74 owner_->Restore();
75 }
76
77 private:
78 // Gets an image representing 3 bitmaps laid out horizontally that will be
79 // used as the normal, hot and pushed states for the created button.
80 views::ImageButton* CreateImageButton(int resource_id) {
81 views::ImageButton* button = new views::ImageButton(this);
82 const SkBitmap* all_images =
83 ResourceBundle::GetSharedInstance().GetImageNamed(
84 resource_id).ToSkBitmap();
85 int width = all_images->width() / 3;
86 int height = all_images->height();
87
88 SkBitmap normal, hot, pushed;
89 all_images->extractSubset(
90 &normal,
91 SkIRect::MakeXYWH(0, 0, width, height));
92 all_images->extractSubset(
93 &hot,
94 SkIRect::MakeXYWH(width, 0, width, height));
95 all_images->extractSubset(
96 &pushed,
97 SkIRect::MakeXYWH(2 * width, 0, width, height));
98 button->SetImage(views::CustomButton::BS_NORMAL, &normal);
99 button->SetImage(views::CustomButton::BS_HOT, &hot);
100 button->SetImage(views::CustomButton::BS_PUSHED, &pushed);
101
102 button->SizeToPreferredSize();
103 return button;
104 }
105
106 AppNonClientFrameViewAura* owner_;
107 views::ImageButton* close_button_;
108 views::ImageButton* restore_button_;
109 SkBitmap separator_;
110 SkBitmap shadow_;
111
112 DISALLOW_COPY_AND_ASSIGN(ControlView);
113 };
114
115 class AppNonClientFrameViewAura::Host : public views::MouseWatcherHost {
116 public:
117 explicit Host(AppNonClientFrameViewAura* owner) : owner_(owner) {}
118 virtual ~Host() {}
119
120 virtual bool Contains(
121 const gfx::Point& screen_point,
122 views::MouseWatcherHost::MouseEventType type) {
123 gfx::Rect top_margin = owner_->GetScreenBounds();
124 top_margin.set_height(kTopMargin);
125 gfx::Rect control_bounds = owner_->GetControlBounds();
126 control_bounds.Inset(kShadowStart, 0, 0, kShadowStart);
127 return top_margin.Contains(screen_point) ||
128 control_bounds.Contains(screen_point);
129 }
130
131 AppNonClientFrameViewAura* owner_;
132
133 DISALLOW_COPY_AND_ASSIGN(Host);
134 };
135
136 AppNonClientFrameViewAura::AppNonClientFrameViewAura(
137 BrowserFrame* frame, BrowserView* browser_view)
138 : BrowserNonClientFrameView(frame, browser_view),
139 control_view_(new ControlView(this)),
140 control_widget_(NULL),
141 ALLOW_THIS_IN_INITIALIZER_LIST(
142 mouse_watcher_(new Host(this), this)) {
143 }
144
145 AppNonClientFrameViewAura::~AppNonClientFrameViewAura() {
146 if (control_widget_) {
147 control_widget_->Close();
148 }
149 }
150
151 gfx::Rect AppNonClientFrameViewAura::GetBoundsForClientView() const {
152 gfx::Rect bounds = GetLocalBounds();
153 bounds.Inset(0, kTopMargin, 0, 0);
154 return bounds;
155 }
156
157 gfx::Rect AppNonClientFrameViewAura::GetWindowBoundsForClientBounds(
158 const gfx::Rect& client_bounds) const {
159 gfx::Rect bounds = client_bounds;
160 bounds.Inset(0, -kTopMargin, 0, 0);
161 return bounds;
162 }
163
164 int AppNonClientFrameViewAura::NonClientHitTest(
165 const gfx::Point& point) {
166 return bounds().Contains(point) ? HTCLIENT : HTNOWHERE;
167 }
168
169 void AppNonClientFrameViewAura::GetWindowMask(const gfx::Size& size,
170 gfx::Path* window_mask) {
171 }
172
173 void AppNonClientFrameViewAura::ResetWindowControls() {
174 }
175
176 void AppNonClientFrameViewAura::UpdateWindowIcon() {
177 }
178
179 gfx::Rect AppNonClientFrameViewAura::GetBoundsForTabStrip(
180 views::View* tabstrip) const {
181 return gfx::Rect();
182 }
183
184 int AppNonClientFrameViewAura::GetHorizontalTabStripVerticalOffset(
185 bool restored) const {
186 return 0;
187 }
188
189 void AppNonClientFrameViewAura::UpdateThrobber(bool running) {
190 }
191
192 void AppNonClientFrameViewAura::OnMouseEntered(
193 const views::MouseEvent& event) {
194 if (!control_widget_) {
195 control_widget_ = new views::Widget;
196 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
197 params.parent = browser_view()->GetNativeHandle();
198 params.transparent = true;
199 control_widget_->Init(params);
200 control_widget_->SetContentsView(control_view_);
201 aura::Window* window = control_widget_->GetNativeView();
202 gfx::Rect control_bounds = GetControlBounds();
203 control_bounds.set_y(control_bounds.y() - control_bounds.height());
204 window->SetBounds(control_bounds);
205 control_widget_->Show();
206 }
207
208 ui::Layer* layer = control_widget_->GetNativeView()->layer();
209 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator());
210 scoped_setter.SetTransitionDuration(
211 base::TimeDelta::FromMilliseconds(kHoverFadeDurationMs));
212 layer->SetBounds(GetControlBounds());
213 layer->SetOpacity(1);
214
215 mouse_watcher_.Start();
216 }
217
218 void AppNonClientFrameViewAura::MouseMovedOutOfHost() {
219 ui::Layer* layer = control_widget_->GetNativeView()->layer();
220
221 ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator());
222 scoped_setter.SetTransitionDuration(
223 base::TimeDelta::FromMilliseconds(kHoverFadeDurationMs));
224 gfx::Rect control_bounds = GetControlBounds();
225 control_bounds.set_y(control_bounds.y() - control_bounds.height());
226 layer->SetBounds(control_bounds);
227 layer->SetOpacity(0);
228 }
229
230 gfx::Rect AppNonClientFrameViewAura::GetControlBounds() const {
231 gfx::Size preferred = control_view_->GetPreferredSize();
232 gfx::Point location(width() - preferred.width(), 0);
233 ConvertPointToWidget(this, &location);
234 return gfx::Rect(
235 location.x(), location.y(),
236 preferred.width(), preferred.height());
237 }
238
239 void AppNonClientFrameViewAura::Close() {
240 control_widget_->Close();
241 control_widget_ = NULL;
242 mouse_watcher_.Stop();
243 frame()->Close();
244 }
245
246 void AppNonClientFrameViewAura::Restore() {
247 control_widget_->Close();
248 control_widget_ = NULL;
249 mouse_watcher_.Stop();
250 frame()->Restore();
251 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/app_non_client_frame_view_aura.h ('k') | chrome/browser/ui/views/frame/browser_frame_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698