OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/frame/custom_frame_view_ash.h" | 5 #include "ash/frame/custom_frame_view_ash.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/frame/caption_buttons/frame_caption_button.h" |
11 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 12 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
12 #include "ash/frame/default_header_painter.h" | 13 #include "ash/frame/default_header_painter.h" |
13 #include "ash/frame/frame_border_hit_test_controller.h" | 14 #include "ash/frame/frame_border_hit_test_controller.h" |
14 #include "ash/frame/header_painter.h" | 15 #include "ash/frame/header_painter.h" |
| 16 #include "ash/frame/header_painter_util.h" |
15 #include "ash/session/session_state_delegate.h" | 17 #include "ash/session/session_state_delegate.h" |
16 #include "ash/shell.h" | 18 #include "ash/shell.h" |
17 #include "ash/shell_observer.h" | 19 #include "ash/shell_observer.h" |
18 #include "ash/wm/immersive_fullscreen_controller.h" | 20 #include "ash/wm/immersive_fullscreen_controller.h" |
19 #include "ash/wm/window_state.h" | 21 #include "ash/wm/window_state.h" |
20 #include "ash/wm/window_state_delegate.h" | 22 #include "ash/wm/window_state_delegate.h" |
21 #include "ash/wm/window_state_observer.h" | 23 #include "ash/wm/window_state_observer.h" |
22 #include "base/command_line.h" | 24 #include "base/command_line.h" |
23 #include "ui/aura/client/aura_constants.h" | 25 #include "ui/aura/client/aura_constants.h" |
24 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
25 #include "ui/aura/window_observer.h" | 27 #include "ui/aura/window_observer.h" |
| 28 #include "ui/base/hit_test.h" |
26 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/geometry/rect.h" | 30 #include "ui/gfx/geometry/rect.h" |
28 #include "ui/gfx/geometry/rect_conversions.h" | 31 #include "ui/gfx/geometry/rect_conversions.h" |
29 #include "ui/gfx/geometry/size.h" | 32 #include "ui/gfx/geometry/size.h" |
30 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
31 #include "ui/views/controls/image_view.h" | 34 #include "ui/views/controls/image_view.h" |
| 35 #include "ui/views/layout/box_layout.h" |
32 #include "ui/views/view.h" | 36 #include "ui/views/view.h" |
33 #include "ui/views/view_targeter.h" | 37 #include "ui/views/view_targeter.h" |
34 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
35 #include "ui/views/widget/widget_delegate.h" | 39 #include "ui/views/widget/widget_delegate.h" |
36 | 40 |
37 namespace { | 41 namespace { |
38 | 42 |
39 /////////////////////////////////////////////////////////////////////////////// | 43 /////////////////////////////////////////////////////////////////////////////// |
40 // CustomFrameViewAshWindowStateDelegate | 44 // CustomFrameViewAshWindowStateDelegate |
41 | 45 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 111 } |
108 } | 112 } |
109 | 113 |
110 ash::wm::WindowState* window_state_; | 114 ash::wm::WindowState* window_state_; |
111 scoped_ptr<ash::ImmersiveFullscreenController> | 115 scoped_ptr<ash::ImmersiveFullscreenController> |
112 immersive_fullscreen_controller_; | 116 immersive_fullscreen_controller_; |
113 | 117 |
114 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshWindowStateDelegate); | 118 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshWindowStateDelegate); |
115 }; | 119 }; |
116 | 120 |
| 121 class LeftHeaderView : public views::View { |
| 122 public: |
| 123 explicit LeftHeaderView(ash::FrameCaptionButton* caption_button) |
| 124 : caption_button_(caption_button) { |
| 125 SetLayoutManager( |
| 126 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 127 AddChildView(caption_button_); |
| 128 caption_button_->SetState(views::Button::STATE_NORMAL); |
| 129 } |
| 130 ~LeftHeaderView() override {} |
| 131 |
| 132 void SetPaintAsActive(bool active) { |
| 133 caption_button_->set_paint_as_active(active); |
| 134 } |
| 135 |
| 136 private: |
| 137 ash::FrameCaptionButton* caption_button_; |
| 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(LeftHeaderView); |
| 140 }; |
| 141 |
| 142 // Combines View::ConvertPointToTarget() and View::HitTest() for a given |
| 143 // |point|. Converts |point| from |src| to |dst| and hit tests it against |dst|. |
| 144 bool ConvertedHitTest(views::View* src, |
| 145 views::View* dst, |
| 146 const gfx::Point& point) { |
| 147 DCHECK(src); |
| 148 DCHECK(dst); |
| 149 gfx::Point converted_point(point); |
| 150 views::View::ConvertPointToTarget(src, dst, &converted_point); |
| 151 return dst->HitTestPoint(converted_point); |
| 152 } |
| 153 |
117 } // namespace | 154 } // namespace |
118 | 155 |
119 namespace ash { | 156 namespace ash { |
120 | 157 |
121 /////////////////////////////////////////////////////////////////////////////// | 158 /////////////////////////////////////////////////////////////////////////////// |
122 // CustomFrameViewAsh::HeaderView | 159 // CustomFrameViewAsh::HeaderView |
123 | 160 |
124 // View which paints the header. It slides off and on screen in immersive | 161 // View which paints the header. It slides off and on screen in immersive |
125 // fullscreen. | 162 // fullscreen. |
126 class CustomFrameViewAsh::HeaderView | 163 class CustomFrameViewAsh::HeaderView |
(...skipping 19 matching lines...) Expand all Loading... |
146 | 183 |
147 // Returns the view's minimum width. | 184 // Returns the view's minimum width. |
148 int GetMinimumWidth() const; | 185 int GetMinimumWidth() const; |
149 | 186 |
150 void UpdateAvatarIcon(); | 187 void UpdateAvatarIcon(); |
151 | 188 |
152 void SizeConstraintsChanged(); | 189 void SizeConstraintsChanged(); |
153 | 190 |
154 void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color); | 191 void SetFrameColors(SkColor active_frame_color, SkColor inactive_frame_color); |
155 | 192 |
| 193 void SetLeftCaptionButton(FrameCaptionButton* left_caption_button); |
| 194 |
156 // views::View: | 195 // views::View: |
157 void Layout() override; | 196 void Layout() override; |
158 void OnPaint(gfx::Canvas* canvas) override; | 197 void OnPaint(gfx::Canvas* canvas) override; |
159 void ChildPreferredSizeChanged(views::View* child) override; | 198 void ChildPreferredSizeChanged(views::View* child) override; |
160 | 199 |
161 // ShellObserver: | 200 // ShellObserver: |
162 void OnMaximizeModeStarted() override; | 201 void OnMaximizeModeStarted() override; |
163 void OnMaximizeModeEnded() override; | 202 void OnMaximizeModeEnded() override; |
164 | 203 |
165 FrameCaptionButtonContainerView* caption_button_container() { | 204 FrameCaptionButtonContainerView* caption_button_container() { |
166 return caption_button_container_; | 205 return caption_button_container_; |
167 } | 206 } |
168 | 207 |
169 views::View* avatar_icon() const { | 208 views::View* avatar_icon() const { |
170 return avatar_icon_; | 209 return avatar_icon_; |
171 } | 210 } |
172 | 211 |
| 212 views::View* left_header_view() const { return left_header_view_; } |
| 213 |
173 private: | 214 private: |
174 // ImmersiveFullscreenController::Delegate: | 215 // ImmersiveFullscreenController::Delegate: |
175 void OnImmersiveRevealStarted() override; | 216 void OnImmersiveRevealStarted() override; |
176 void OnImmersiveRevealEnded() override; | 217 void OnImmersiveRevealEnded() override; |
177 void OnImmersiveFullscreenExited() override; | 218 void OnImmersiveFullscreenExited() override; |
178 void SetVisibleFraction(double visible_fraction) override; | 219 void SetVisibleFraction(double visible_fraction) override; |
179 std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override; | 220 std::vector<gfx::Rect> GetVisibleBoundsInScreen() const override; |
180 | 221 |
181 // The widget that the caption buttons act on. | 222 // The widget that the caption buttons act on. |
182 views::Widget* frame_; | 223 views::Widget* frame_; |
183 | 224 |
184 // Helper for painting the header. | 225 // Helper for painting the header. |
185 scoped_ptr<DefaultHeaderPainter> header_painter_; | 226 scoped_ptr<DefaultHeaderPainter> header_painter_; |
186 | 227 |
187 views::ImageView* avatar_icon_; | 228 views::ImageView* avatar_icon_; |
188 | 229 |
189 // View which contains the window caption buttons. | 230 // View which contains the window caption buttons. |
190 FrameCaptionButtonContainerView* caption_button_container_; | 231 FrameCaptionButtonContainerView* caption_button_container_; |
191 | 232 |
| 233 // View which contains the left caption button. |
| 234 LeftHeaderView* left_header_view_; |
| 235 |
192 // The fraction of the header's height which is visible while in fullscreen. | 236 // The fraction of the header's height which is visible while in fullscreen. |
193 // This value is meaningless when not in fullscreen. | 237 // This value is meaningless when not in fullscreen. |
194 double fullscreen_visible_fraction_; | 238 double fullscreen_visible_fraction_; |
195 | 239 |
196 DISALLOW_COPY_AND_ASSIGN(HeaderView); | 240 DISALLOW_COPY_AND_ASSIGN(HeaderView); |
197 }; | 241 }; |
198 | 242 |
199 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) | 243 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) |
200 : frame_(frame), | 244 : frame_(frame), |
201 header_painter_(new ash::DefaultHeaderPainter), | 245 header_painter_(new ash::DefaultHeaderPainter), |
202 avatar_icon_(NULL), | 246 avatar_icon_(NULL), |
203 caption_button_container_(NULL), | 247 caption_button_container_(NULL), |
| 248 left_header_view_(NULL), |
204 fullscreen_visible_fraction_(0) { | 249 fullscreen_visible_fraction_(0) { |
205 caption_button_container_ = new FrameCaptionButtonContainerView(frame_); | 250 caption_button_container_ = new FrameCaptionButtonContainerView(frame_); |
206 caption_button_container_->UpdateSizeButtonVisibility(); | 251 caption_button_container_->UpdateSizeButtonVisibility(); |
207 AddChildView(caption_button_container_); | 252 AddChildView(caption_button_container_); |
208 | 253 |
209 header_painter_->Init(frame_, this, caption_button_container_); | 254 header_painter_->Init(frame_, this, caption_button_container_); |
210 UpdateAvatarIcon(); | 255 UpdateAvatarIcon(); |
211 | 256 |
212 Shell::GetInstance()->AddShellObserver(this); | 257 Shell::GetInstance()->AddShellObserver(this); |
213 } | 258 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 caption_button_container_->ResetWindowControls(); | 312 caption_button_container_->ResetWindowControls(); |
268 caption_button_container_->UpdateSizeButtonVisibility(); | 313 caption_button_container_->UpdateSizeButtonVisibility(); |
269 Layout(); | 314 Layout(); |
270 } | 315 } |
271 | 316 |
272 void CustomFrameViewAsh::HeaderView::SetFrameColors( | 317 void CustomFrameViewAsh::HeaderView::SetFrameColors( |
273 SkColor active_frame_color, SkColor inactive_frame_color) { | 318 SkColor active_frame_color, SkColor inactive_frame_color) { |
274 header_painter_->SetFrameColors(active_frame_color, inactive_frame_color); | 319 header_painter_->SetFrameColors(active_frame_color, inactive_frame_color); |
275 } | 320 } |
276 | 321 |
| 322 void CustomFrameViewAsh::HeaderView::SetLeftCaptionButton( |
| 323 FrameCaptionButton* left_caption_button) { |
| 324 if (left_header_view_) |
| 325 delete left_header_view_; |
| 326 left_header_view_ = new LeftHeaderView(left_caption_button); |
| 327 AddChildView(left_header_view_); |
| 328 header_painter_->UpdateLeftHeaderView(left_header_view_); |
| 329 Layout(); |
| 330 } |
| 331 |
277 /////////////////////////////////////////////////////////////////////////////// | 332 /////////////////////////////////////////////////////////////////////////////// |
278 // CustomFrameViewAsh::HeaderView, views::View overrides: | 333 // CustomFrameViewAsh::HeaderView, views::View overrides: |
279 | 334 |
280 void CustomFrameViewAsh::HeaderView::Layout() { | 335 void CustomFrameViewAsh::HeaderView::Layout() { |
281 header_painter_->LayoutHeader(); | 336 header_painter_->LayoutHeader(); |
| 337 if (left_header_view_) { |
| 338 header_painter_->UpdateLeftViewXInset(0); |
| 339 } else { |
| 340 header_painter_->UpdateLeftViewXInset( |
| 341 ash::HeaderPainterUtil::GetDefaultLeftViewXInset()); |
| 342 } |
282 } | 343 } |
283 | 344 |
284 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { | 345 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { |
285 bool paint_as_active = | 346 bool paint_as_active = |
286 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); | 347 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); |
287 caption_button_container_->SetPaintAsActive(paint_as_active); | 348 caption_button_container_->SetPaintAsActive(paint_as_active); |
288 | 349 if (left_header_view_) |
| 350 left_header_view_->SetPaintAsActive(paint_as_active); |
289 HeaderPainter::Mode header_mode = paint_as_active ? | 351 HeaderPainter::Mode header_mode = paint_as_active ? |
290 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE; | 352 HeaderPainter::MODE_ACTIVE : HeaderPainter::MODE_INACTIVE; |
291 header_painter_->PaintHeader(canvas, header_mode); | 353 header_painter_->PaintHeader(canvas, header_mode); |
292 } | 354 } |
293 | 355 |
294 void CustomFrameViewAsh::HeaderView:: | 356 void CustomFrameViewAsh::HeaderView:: |
295 ChildPreferredSizeChanged(views::View* child) { | 357 ChildPreferredSizeChanged(views::View* child) { |
296 // FrameCaptionButtonContainerView animates the visibility changes in | 358 // FrameCaptionButtonContainerView animates the visibility changes in |
297 // UpdateSizeButtonVisibility(false). Due to this a new size is not available | 359 // UpdateSizeButtonVisibility(false). Due to this a new size is not available |
298 // until the completion of the animation. Layout in response to the preferred | 360 // until the completion of the animation. Layout in response to the preferred |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( | 516 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( |
455 ImmersiveFullscreenController* immersive_fullscreen_controller) { | 517 ImmersiveFullscreenController* immersive_fullscreen_controller) { |
456 immersive_fullscreen_controller->Init(header_view_, frame_, header_view_); | 518 immersive_fullscreen_controller->Init(header_view_, frame_, header_view_); |
457 } | 519 } |
458 | 520 |
459 void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color, | 521 void CustomFrameViewAsh::SetFrameColors(SkColor active_frame_color, |
460 SkColor inactive_frame_color) { | 522 SkColor inactive_frame_color) { |
461 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); | 523 header_view_->SetFrameColors(active_frame_color, inactive_frame_color); |
462 } | 524 } |
463 | 525 |
| 526 void CustomFrameViewAsh::SetLeftCaptionButton( |
| 527 FrameCaptionButton* left_caption_button) { |
| 528 header_view_->SetLeftCaptionButton(left_caption_button); |
| 529 } |
| 530 |
464 //////////////////////////////////////////////////////////////////////////////// | 531 //////////////////////////////////////////////////////////////////////////////// |
465 // CustomFrameViewAsh, views::NonClientFrameView overrides: | 532 // CustomFrameViewAsh, views::NonClientFrameView overrides: |
466 | 533 |
467 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { | 534 gfx::Rect CustomFrameViewAsh::GetBoundsForClientView() const { |
468 gfx::Rect client_bounds = bounds(); | 535 gfx::Rect client_bounds = bounds(); |
469 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); | 536 client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0); |
470 return client_bounds; | 537 return client_bounds; |
471 } | 538 } |
472 | 539 |
473 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds( | 540 gfx::Rect CustomFrameViewAsh::GetWindowBoundsForClientBounds( |
474 const gfx::Rect& client_bounds) const { | 541 const gfx::Rect& client_bounds) const { |
475 gfx::Rect window_bounds = client_bounds; | 542 gfx::Rect window_bounds = client_bounds; |
476 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0); | 543 window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0); |
477 return window_bounds; | 544 return window_bounds; |
478 } | 545 } |
479 | 546 |
480 int CustomFrameViewAsh::NonClientHitTest(const gfx::Point& point) { | 547 int CustomFrameViewAsh::NonClientHitTest(const gfx::Point& point) { |
481 return FrameBorderHitTestController::NonClientHitTest(this, | 548 int hit_test = FrameBorderHitTestController::NonClientHitTest( |
482 header_view_->caption_button_container(), point); | 549 this, header_view_->caption_button_container(), point); |
| 550 |
| 551 // See if the point is actually within the left header view. |
| 552 if (hit_test == HTCAPTION && header_view_->left_header_view() && |
| 553 ConvertedHitTest(this, header_view_->left_header_view(), point)) { |
| 554 return HTCLIENT; |
| 555 } |
| 556 |
| 557 return hit_test; |
483 } | 558 } |
484 | 559 |
485 void CustomFrameViewAsh::GetWindowMask(const gfx::Size& size, | 560 void CustomFrameViewAsh::GetWindowMask(const gfx::Size& size, |
486 gfx::Path* window_mask) { | 561 gfx::Path* window_mask) { |
487 // No window masks in Aura. | 562 // No window masks in Aura. |
488 } | 563 } |
489 | 564 |
490 void CustomFrameViewAsh::ResetWindowControls() { | 565 void CustomFrameViewAsh::ResetWindowControls() { |
491 header_view_->ResetWindowControls(); | 566 header_view_->ResetWindowControls(); |
492 } | 567 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 FrameCaptionButtonContainerView* CustomFrameViewAsh:: | 656 FrameCaptionButtonContainerView* CustomFrameViewAsh:: |
582 GetFrameCaptionButtonContainerViewForTest() { | 657 GetFrameCaptionButtonContainerViewForTest() { |
583 return header_view_->caption_button_container(); | 658 return header_view_->caption_button_container(); |
584 } | 659 } |
585 | 660 |
586 int CustomFrameViewAsh::NonClientTopBorderHeight() const { | 661 int CustomFrameViewAsh::NonClientTopBorderHeight() const { |
587 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); | 662 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); |
588 } | 663 } |
589 | 664 |
590 } // namespace ash | 665 } // namespace ash |
OLD | NEW |