OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/ash_layout_constants.h" | 9 #include "ash/ash_layout_constants.h" |
10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "ui/views/layout/layout_constants.h" | 51 #include "ui/views/layout/layout_constants.h" |
52 #include "ui/views/widget/widget.h" | 52 #include "ui/views/widget/widget.h" |
53 #include "ui/views/widget/widget_delegate.h" | 53 #include "ui/views/widget/widget_delegate.h" |
54 | 54 |
55 #if defined(ENABLE_SUPERVISED_USERS) | 55 #if defined(ENABLE_SUPERVISED_USERS) |
56 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h" | 56 #include "chrome/browser/ui/views/profiles/supervised_user_avatar_label.h" |
57 #endif | 57 #endif |
58 | 58 |
59 namespace { | 59 namespace { |
60 | 60 |
61 #if defined(FRAME_AVATAR_BUTTON) | |
62 // Space between the new avatar button and the minimize button. | |
63 const int kNewAvatarButtonOffset = 5; | |
64 #endif | |
65 // Space between right edge of tabstrip and maximize button. | 61 // Space between right edge of tabstrip and maximize button. |
66 const int kTabstripRightSpacing = 10; | 62 const int kTabstripRightSpacing = 10; |
67 // Height of the shadow of the content area, at the top of the toolbar. | 63 // Height of the shadow of the content area, at the top of the toolbar. |
68 const int kContentShadowHeight = 1; | 64 const int kContentShadowHeight = 1; |
69 // Space between top of window and top of tabstrip for tall headers, such as | 65 // Space between top of window and top of tabstrip for tall headers, such as |
70 // for restored windows, apps, etc. | 66 // for restored windows, apps, etc. |
71 const int kTabstripTopSpacingTall = 7; | 67 const int kTabstripTopSpacingTall = 7; |
72 // Space between top of window and top of tabstrip for short headers, such as | 68 // Space between top of window and top of tabstrip for short headers, such as |
73 // for maximized windows, pop-ups, etc. | 69 // for maximized windows, pop-ups, etc. |
74 const int kTabstripTopSpacingShort = 0; | 70 const int kTabstripTopSpacingShort = 0; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 235 |
240 gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds( | 236 gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds( |
241 const gfx::Rect& client_bounds) const { | 237 const gfx::Rect& client_bounds) const { |
242 return client_bounds; | 238 return client_bounds; |
243 } | 239 } |
244 | 240 |
245 int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) { | 241 int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) { |
246 int hit_test = ash::FrameBorderHitTestController::NonClientHitTest(this, | 242 int hit_test = ash::FrameBorderHitTestController::NonClientHitTest(this, |
247 caption_button_container_, point); | 243 caption_button_container_, point); |
248 | 244 |
249 #if defined(FRAME_AVATAR_BUTTON) | |
250 if (hit_test == HTCAPTION && new_avatar_button() && | |
251 ConvertedHitTest(this, new_avatar_button(), point)) { | |
252 return HTCLIENT; | |
253 } | |
254 #endif | |
255 | |
256 // See if the point is actually within the web app back button. | 245 // See if the point is actually within the web app back button. |
257 if (hit_test == HTCAPTION && web_app_left_header_view_ && | 246 if (hit_test == HTCAPTION && web_app_left_header_view_ && |
258 ConvertedHitTest(this, web_app_left_header_view_, point)) { | 247 ConvertedHitTest(this, web_app_left_header_view_, point)) { |
259 return HTCLIENT; | 248 return HTCLIENT; |
260 } | 249 } |
261 | 250 |
262 #if defined(ENABLE_SUPERVISED_USERS) | 251 #if defined(ENABLE_SUPERVISED_USERS) |
263 // ...or within the avatar label, if it's a supervised user. | 252 // ...or within the avatar label, if it's a supervised user. |
264 if (hit_test == HTCAPTION && supervised_user_avatar_label() && | 253 if (hit_test == HTCAPTION && supervised_user_avatar_label() && |
265 ConvertedHitTest(this, supervised_user_avatar_label(), point)) { | 254 ConvertedHitTest(this, supervised_user_avatar_label(), point)) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 // toolbar because the top few pixels of the toolbar are not opaque. | 338 // toolbar because the top few pixels of the toolbar are not opaque. |
350 const int kToolbarTopEdgeExclusion = 2; | 339 const int kToolbarTopEdgeExclusion = 2; |
351 painted_height += kToolbarTopEdgeExclusion; | 340 painted_height += kToolbarTopEdgeExclusion; |
352 } | 341 } |
353 header_painter_->SetHeaderHeightForPainting(painted_height); | 342 header_painter_->SetHeaderHeightForPainting(painted_height); |
354 | 343 |
355 if (avatar_button()) { | 344 if (avatar_button()) { |
356 LayoutAvatar(); | 345 LayoutAvatar(); |
357 header_painter_->UpdateLeftViewXInset(avatar_button()->bounds().right()); | 346 header_painter_->UpdateLeftViewXInset(avatar_button()->bounds().right()); |
358 } | 347 } |
359 #if defined(FRAME_AVATAR_BUTTON) | |
360 if (new_avatar_button()) | |
361 LayoutNewStyleAvatar(); | |
362 #endif | |
363 header_painter_->UpdateLeftViewXInset( | 348 header_painter_->UpdateLeftViewXInset( |
364 ash::HeaderPainterUtil::GetDefaultLeftViewXInset()); | 349 ash::HeaderPainterUtil::GetDefaultLeftViewXInset()); |
365 BrowserNonClientFrameView::Layout(); | 350 BrowserNonClientFrameView::Layout(); |
366 } | 351 } |
367 | 352 |
368 const char* BrowserNonClientFrameViewAsh::GetClassName() const { | 353 const char* BrowserNonClientFrameViewAsh::GetClassName() const { |
369 return kViewClassName; | 354 return kViewClassName; |
370 } | 355 } |
371 | 356 |
372 void BrowserNonClientFrameViewAsh::GetAccessibleState( | 357 void BrowserNonClientFrameViewAsh::GetAccessibleState( |
(...skipping 17 matching lines...) Expand all Loading... |
390 } | 375 } |
391 | 376 |
392 void BrowserNonClientFrameViewAsh:: | 377 void BrowserNonClientFrameViewAsh:: |
393 ChildPreferredSizeChanged(views::View* child) { | 378 ChildPreferredSizeChanged(views::View* child) { |
394 // FrameCaptionButtonContainerView animates the visibility changes in | 379 // FrameCaptionButtonContainerView animates the visibility changes in |
395 // UpdateSizeButtonVisibility(false). Due to this a new size is not available | 380 // UpdateSizeButtonVisibility(false). Due to this a new size is not available |
396 // until the completion of the animation. Layout in response to the preferred | 381 // until the completion of the animation. Layout in response to the preferred |
397 // size changes. | 382 // size changes. |
398 if (!browser_view()->initialized()) | 383 if (!browser_view()->initialized()) |
399 return; | 384 return; |
400 bool needs_layout = child == caption_button_container_; | 385 if (child == caption_button_container_) { |
401 #if defined(FRAME_AVATAR_BUTTON) | |
402 needs_layout = needs_layout || child == new_avatar_button(); | |
403 #endif | |
404 if (needs_layout) { | |
405 InvalidateLayout(); | 386 InvalidateLayout(); |
406 frame()->GetRootView()->Layout(); | 387 frame()->GetRootView()->Layout(); |
407 } | 388 } |
408 } | 389 } |
409 | 390 |
410 /////////////////////////////////////////////////////////////////////////////// | 391 /////////////////////////////////////////////////////////////////////////////// |
411 // ash::ShellObserver: | 392 // ash::ShellObserver: |
412 | 393 |
413 void BrowserNonClientFrameViewAsh::OnMaximizeModeStarted() { | 394 void BrowserNonClientFrameViewAsh::OnMaximizeModeStarted() { |
414 caption_button_container_->UpdateSizeButtonVisibility(); | 395 caption_button_container_->UpdateSizeButtonVisibility(); |
(...skipping 21 matching lines...) Expand all Loading... |
436 } | 417 } |
437 | 418 |
438 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() { | 419 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() { |
439 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 420 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
440 if (!delegate) | 421 if (!delegate) |
441 return gfx::ImageSkia(); | 422 return gfx::ImageSkia(); |
442 return delegate->GetWindowIcon(); | 423 return delegate->GetWindowIcon(); |
443 } | 424 } |
444 | 425 |
445 /////////////////////////////////////////////////////////////////////////////// | 426 /////////////////////////////////////////////////////////////////////////////// |
446 // views::ButtonListener: | |
447 | |
448 void BrowserNonClientFrameViewAsh::ButtonPressed(views::Button* sender, | |
449 const ui::Event& event) { | |
450 #if !defined(FRAME_AVATAR_BUTTON) | |
451 NOTREACHED(); | |
452 #else | |
453 DCHECK(sender == new_avatar_button()); | |
454 int command = IDC_SHOW_AVATAR_MENU; | |
455 if (event.IsMouseEvent() && | |
456 static_cast<const ui::MouseEvent&>(event).IsRightMouseButton()) { | |
457 command = IDC_SHOW_FAST_USER_SWITCHER; | |
458 } | |
459 chrome::ExecuteCommand(browser_view()->browser(), command); | |
460 #endif | |
461 } | |
462 | |
463 /////////////////////////////////////////////////////////////////////////////// | |
464 // BrowserNonClientFrameViewAsh, protected: | 427 // BrowserNonClientFrameViewAsh, protected: |
465 | 428 |
466 // BrowserNonClientFrameView: | 429 // BrowserNonClientFrameView: |
467 void BrowserNonClientFrameViewAsh::UpdateNewAvatarButtonImpl() { | 430 void BrowserNonClientFrameViewAsh::UpdateNewAvatarButtonImpl() { |
468 #if defined(FRAME_AVATAR_BUTTON) | 431 NOTREACHED(); |
469 UpdateNewAvatarButton(this, NewAvatarButton::NATIVE_BUTTON); | |
470 #endif | |
471 } | 432 } |
472 | 433 |
473 /////////////////////////////////////////////////////////////////////////////// | 434 /////////////////////////////////////////////////////////////////////////////// |
474 // BrowserNonClientFrameViewAsh, private: | 435 // BrowserNonClientFrameViewAsh, private: |
475 | 436 |
476 // views::NonClientFrameView: | 437 // views::NonClientFrameView: |
477 bool BrowserNonClientFrameViewAsh::DoesIntersectRect( | 438 bool BrowserNonClientFrameViewAsh::DoesIntersectRect( |
478 const views::View* target, | 439 const views::View* target, |
479 const gfx::Rect& rect) const { | 440 const gfx::Rect& rect) const { |
480 CHECK_EQ(target, this); | 441 CHECK_EQ(target, this); |
(...skipping 26 matching lines...) Expand all Loading... |
507 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); | 468 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); |
508 const int avatar_right = avatar_button() ? | 469 const int avatar_right = avatar_button() ? |
509 (insets.left() + browser_view()->GetOTRAvatarIcon().width()) : 0; | 470 (insets.left() + browser_view()->GetOTRAvatarIcon().width()) : 0; |
510 return avatar_right + insets.right(); | 471 return avatar_right + insets.right(); |
511 } | 472 } |
512 | 473 |
513 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { | 474 int BrowserNonClientFrameViewAsh::GetTabStripRightInset() const { |
514 int tabstrip_width = kTabstripRightSpacing + | 475 int tabstrip_width = kTabstripRightSpacing + |
515 caption_button_container_->GetPreferredSize().width(); | 476 caption_button_container_->GetPreferredSize().width(); |
516 | 477 |
517 #if defined(FRAME_AVATAR_BUTTON) | |
518 if (new_avatar_button()) { | |
519 tabstrip_width += kNewAvatarButtonOffset + | |
520 new_avatar_button()->GetPreferredSize().width(); | |
521 } | |
522 #endif | |
523 | |
524 return tabstrip_width; | 478 return tabstrip_width; |
525 } | 479 } |
526 | 480 |
527 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { | 481 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { |
528 ImmersiveModeController* immersive_controller = | 482 ImmersiveModeController* immersive_controller = |
529 browser_view()->immersive_mode_controller(); | 483 browser_view()->immersive_mode_controller(); |
530 return immersive_controller->IsEnabled() && | 484 return immersive_controller->IsEnabled() && |
531 !immersive_controller->IsRevealed() && | 485 !immersive_controller->IsRevealed() && |
532 browser_view()->IsTabStripVisible(); | 486 browser_view()->IsTabStripVisible(); |
533 } | 487 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 // recognizable. | 524 // recognizable. |
571 bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); | 525 bool avatar_visible = !UseImmersiveLightbarHeaderStyle(); |
572 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0; | 526 int avatar_height = avatar_visible ? avatar_bottom - avatar_y : 0; |
573 | 527 |
574 gfx::Rect avatar_bounds(avatar_insets.left(), avatar_y, | 528 gfx::Rect avatar_bounds(avatar_insets.left(), avatar_y, |
575 incognito_icon.width(), avatar_height); | 529 incognito_icon.width(), avatar_height); |
576 avatar_button()->SetBoundsRect(avatar_bounds); | 530 avatar_button()->SetBoundsRect(avatar_bounds); |
577 avatar_button()->SetVisible(avatar_visible); | 531 avatar_button()->SetVisible(avatar_visible); |
578 } | 532 } |
579 | 533 |
580 #if defined(FRAME_AVATAR_BUTTON) | |
581 void BrowserNonClientFrameViewAsh::LayoutNewStyleAvatar() { | |
582 DCHECK(new_avatar_button()); | |
583 | |
584 gfx::Size button_size = new_avatar_button()->GetPreferredSize(); | |
585 int button_x = width() - | |
586 caption_button_container_->GetPreferredSize().width() - | |
587 kNewAvatarButtonOffset - button_size.width(); | |
588 | |
589 new_avatar_button()->SetBounds( | |
590 button_x, | |
591 0, | |
592 button_size.width(), | |
593 caption_button_container_->GetPreferredSize().height()); | |
594 } | |
595 #endif | |
596 | |
597 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { | 534 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { |
598 if (!frame()->IsFullscreen()) | 535 if (!frame()->IsFullscreen()) |
599 return true; | 536 return true; |
600 | 537 |
601 // We need to paint when in immersive fullscreen and either: | 538 // We need to paint when in immersive fullscreen and either: |
602 // - The top-of-window views are revealed. | 539 // - The top-of-window views are revealed. |
603 // - The lightbar style tabstrip is visible. | 540 // - The lightbar style tabstrip is visible. |
604 ImmersiveModeController* immersive_mode_controller = | 541 ImmersiveModeController* immersive_mode_controller = |
605 browser_view()->immersive_mode_controller(); | 542 browser_view()->immersive_mode_controller(); |
606 return immersive_mode_controller->IsEnabled() && | 543 return immersive_mode_controller->IsEnabled() && |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 } | 666 } |
730 | 667 |
731 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) { | 668 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) { |
732 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle()); | 669 DCHECK(!UsePackagedAppHeaderStyle() && !UseWebAppHeaderStyle()); |
733 canvas->FillRect( | 670 canvas->FillRect( |
734 gfx::Rect(0, caption_button_container_->bounds().bottom(), width(), | 671 gfx::Rect(0, caption_button_container_->bounds().bottom(), width(), |
735 kClientEdgeThickness), | 672 kClientEdgeThickness), |
736 GetThemeProvider()->GetColor( | 673 GetThemeProvider()->GetColor( |
737 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); | 674 ThemeProperties::COLOR_TOOLBAR_BOTTOM_SEPARATOR)); |
738 } | 675 } |
OLD | NEW |