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/toolbar_view.h" | 5 #include "chrome/browser/ui/views/toolbar_view.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 case IDC_FEEDBACK: | 597 case IDC_FEEDBACK: |
598 *accelerator = ui::Accelerator(ui::VKEY_I, | 598 *accelerator = ui::Accelerator(ui::VKEY_I, |
599 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); | 599 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
600 return true; | 600 return true; |
601 #endif | 601 #endif |
602 } | 602 } |
603 // Else, we retrieve the accelerator information from the frame. | 603 // Else, we retrieve the accelerator information from the frame. |
604 return GetWidget()->GetAccelerator(command_id, accelerator); | 604 return GetWidget()->GetAccelerator(command_id, accelerator); |
605 } | 605 } |
606 | 606 |
| 607 float GetScaleFactor() { |
| 608 switch (ui::GetMaxScaleFactor()) { |
| 609 case ui::SCALE_FACTOR_140P: |
| 610 return 1.4f; |
| 611 case ui::SCALE_FACTOR_180P: |
| 612 return 1.8f; |
| 613 } |
| 614 return 1.0f; |
| 615 } |
| 616 |
607 //////////////////////////////////////////////////////////////////////////////// | 617 //////////////////////////////////////////////////////////////////////////////// |
608 // ToolbarView, views::View overrides: | 618 // ToolbarView, views::View overrides: |
609 | 619 |
610 gfx::Size ToolbarView::GetPreferredSize() { | 620 gfx::Size ToolbarView::GetPreferredSize() { |
| 621 float scale = 1; // GetScaleFactor(); |
611 if (is_display_mode_normal()) { | 622 if (is_display_mode_normal()) { |
612 int min_width = kLeftEdgeSpacing + | 623 int min_width = kLeftEdgeSpacing + |
613 back_->GetPreferredSize().width() + kButtonSpacing + | 624 back_->GetPreferredSize().width() + kButtonSpacing + |
614 forward_->GetPreferredSize().width() + kButtonSpacing + | 625 forward_->GetPreferredSize().width() + kButtonSpacing + |
615 reload_->GetPreferredSize().width() + kStandardSpacing + | 626 reload_->GetPreferredSize().width() + kStandardSpacing + |
616 (show_home_button_.GetValue() ? | 627 (show_home_button_.GetValue() ? |
617 (home_->GetPreferredSize().width() + kButtonSpacing) : 0) + | 628 (home_->GetPreferredSize().width() + kButtonSpacing) : 0) + |
618 location_bar_->GetPreferredSize().width() + | 629 location_bar_->GetPreferredSize().width() + |
619 browser_actions_->GetPreferredSize().width() + | 630 browser_actions_->GetPreferredSize().width() + |
620 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; | 631 app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; |
621 gfx::ImageSkia* normal_background = | 632 gfx::ImageSkia* normal_background = |
622 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); | 633 GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
623 return gfx::Size(min_width, | 634 return gfx::Size(min_width * scale, |
624 normal_background->height() - content_shadow_height()); | 635 (normal_background->height() - kContentShadowHeight) * scal
e); |
625 } | 636 } |
626 | 637 |
627 int vertical_spacing = PopupTopSpacing() + | 638 int vertical_spacing = PopupTopSpacing() + |
628 (GetWidget()->ShouldUseNativeFrame() ? | 639 (GetWidget()->ShouldUseNativeFrame() ? |
629 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); | 640 kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); |
630 return gfx::Size(0, location_bar_->GetPreferredSize().height() + | 641 return gfx::Size(0, (location_bar_->GetPreferredSize().height() + |
631 vertical_spacing); | 642 vertical_spacing) * scale); |
| 643 } |
| 644 |
| 645 #include "/gtools.h" |
| 646 void Debug(const gfx::Rect& bounds, LPCTSTR message) { |
| 647 Debug(L"%s (%d, %d, %d, %d)", message, bounds.x(), bounds.y(), bounds.width(),
bounds.height()); |
632 } | 648 } |
633 | 649 |
634 void ToolbarView::Layout() { | 650 void ToolbarView::Layout() { |
635 // If we have not been initialized yet just do nothing. | 651 // If we have not been initialized yet just do nothing. |
636 if (back_ == NULL) | 652 if (back_ == NULL) |
637 return; | 653 return; |
638 | 654 |
| 655 // Layout is done in screen (non-dip) pixels. |
| 656 |
639 bool maximized = browser_->window() && browser_->window()->IsMaximized(); | 657 bool maximized = browser_->window() && browser_->window()->IsMaximized(); |
640 if (!is_display_mode_normal()) { | 658 if (!is_display_mode_normal()) { |
641 int edge_width = maximized ? | 659 int edge_width = maximized ? |
642 0 : kPopupBackgroundEdge->width(); // See OnPaint(). | 660 0 : kPopupBackgroundEdge->width(); // See OnPaint(). |
643 location_bar_->SetBounds(edge_width, PopupTopSpacing(), | 661 location_bar_->SetBounds(edge_width, PopupTopSpacing(), |
644 width() - (edge_width * 2), location_bar_->GetPreferredSize().height()); | 662 width() - (edge_width * 2), location_bar_->GetPreferredSize().height()); |
645 return; | 663 return; |
646 } | 664 } |
| 665 float scale = GetScaleFactor(); |
| 666 float wscale = scale;// = 1; |
647 | 667 |
| 668 Debug(back_->bounds(), L"Original back"); |
| 669 Debug(this->bounds(), L"This bounds"); |
648 // We assume all child elements are the same height. | 670 // We assume all child elements are the same height. |
649 int child_height = | 671 int child_height = |
650 std::min(back_->GetPreferredSize().height(), height()); | 672 std::min((int)(scale * back_->GetPreferredSize().height()), height()); |
651 | 673 |
652 // Set child_y such that buttons appear vertically centered. To preseve | 674 // Set child_y such that buttons appear vertically centered. To preseve |
653 // the behaviour on non-touch UIs, round-up by taking | 675 // the behaviour on non-touch UIs, round-up by taking |
654 // ceil((height() - child_height) / 2) + delta | 676 // ceil((height() - child_height) / 2) + delta |
655 // which is equivalent to the below. | 677 // which is equivalent to the below. |
656 int child_y = (1 + ((height() - child_height - 1) / 2)); | 678 int child_y = (1 + ((height() - child_height - 1) / 2)); |
657 | 679 |
658 // If the window is maximized, we extend the back button to the left so that | 680 // If the window is maximized, we extend the back button to the left so that |
659 // clicking on the left-most pixel will activate the back button. | 681 // clicking on the left-most pixel will activate the back button. |
660 // TODO(abarth): If the window becomes maximized but is not resized, | 682 // TODO(abarth): If the window becomes maximized but is not resized, |
661 // then Layout() might not be called and the back button | 683 // then Layout() might not be called and the back button |
662 // will be slightly the wrong size. We should force a | 684 // will be slightly the wrong size. We should force a |
663 // Layout() in this case. | 685 // Layout() in this case. |
664 // http://crbug.com/5540 | 686 // http://crbug.com/5540 |
665 int back_width = back_->GetPreferredSize().width(); | 687 int back_width = back_->GetPreferredSize().width(); |
666 if (maximized) | 688 if (maximized) |
667 back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); | 689 back_->SetBounds(0, scale * child_y, scale * (back_width + kLeftEdgeSpacing)
, scale * child_height); |
668 else | 690 else |
669 back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); | 691 back_->SetBounds(scale * kLeftEdgeSpacing, scale * child_y, wscale * back_wi
dth, scale * child_height); |
| 692 Debug(back_->bounds(), L"Back"); |
| 693 forward_->SetBounds((back_->x() + back_->width() + scale * kButtonSpacing), |
| 694 scale * child_y, wscale * forward_->GetPreferredSize().width(), scale * ch
ild_height); |
| 695 Debug(forward_->bounds(), L"Forward"); |
670 | 696 |
671 forward_->SetBounds(back_->x() + back_->width() + kButtonSpacing, | 697 gfx::Size reloadSize = reload_->GetPreferredSize(); |
672 child_y, forward_->GetPreferredSize().width(), child_height); | 698 reload_->SetBounds((forward_->x() + forward_->width() + scale * kButtonSpacing
), |
673 | 699 scale * child_y, wscale * reload_->GetPreferredSize().width(), scale * chi
ld_height); |
674 reload_->SetBounds(forward_->x() + forward_->width() + kButtonSpacing, | 700 Debug(reload_->bounds(), L"Reload"); |
675 child_y, reload_->GetPreferredSize().width(), child_height); | |
676 | |
677 if (show_home_button_.GetValue()) { | 701 if (show_home_button_.GetValue()) { |
678 home_->SetVisible(true); | 702 home_->SetVisible(true); |
679 home_->SetBounds(reload_->x() + reload_->width() + kButtonSpacing, child_y, | 703 home_->SetBounds((reload_->x() + reload_->width() + scale * kButtonSpacing),
scale * child_y, |
680 home_->GetPreferredSize().width(), child_height); | 704 wscale * home_->GetPreferredSize().width(), scale * child_h
eight); |
681 } else { | 705 } else { |
682 home_->SetVisible(false); | 706 home_->SetVisible(false); |
683 home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); | 707 home_->SetBounds(reload_->x() + reload_->width(), scale * child_y, 0, scale
* child_height); |
684 } | 708 } |
685 | 709 Debug(home_->bounds(), L"Home"); |
686 int browser_actions_width = browser_actions_->GetPreferredSize().width(); | 710 int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
687 int app_menu_width = app_menu_->GetPreferredSize().width(); | 711 int app_menu_width = app_menu_->GetPreferredSize().width(); |
688 int location_x = home_->x() + home_->width() + kStandardSpacing; | 712 int location_x = home_->x() + home_->width() + scale * kStandardSpacing; |
689 int available_width = std::max(0, width() - kRightEdgeSpacing - | 713 int available_width = std::max(0, width() - kRightEdgeSpacing - |
690 app_menu_width - browser_actions_width - location_x); | 714 app_menu_width - (int)(scale * browser_actions_width) - location_x); |
691 | 715 |
692 int location_y = std::min(location_bar_vert_spacing(), height()); | 716 int location_y = scale * std::min(location_bar_vert_spacing(), height()); |
693 int location_bar_height = location_bar_->GetPreferredSize().height(); | 717 int location_bar_height = location_bar_->GetPreferredSize().height(); |
| 718 location_bar_height = child_height; |
694 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), | 719 location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), |
695 location_bar_height); | 720 scale * location_bar_height); |
696 | 721 |
697 browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, | 722 Debug(location_bar_->bounds(), L"LocationBar"); |
698 browser_actions_width, height()); | 723 browser_actions_->SetBounds((location_bar_->x() + location_bar_->width()), 0, |
| 724 wscale * browser_actions_width, /*scale **/ height
()); |
| 725 Debug(browser_actions_->bounds(), L"BrowserAction"); |
699 // The browser actions need to do a layout explicitly, because when an | 726 // The browser actions need to do a layout explicitly, because when an |
700 // extension is loaded/unloaded/changed, BrowserActionContainer removes and | 727 // extension is loaded/unloaded/changed, BrowserActionContainer removes and |
701 // re-adds everything, regardless of whether it has a page action. For a | 728 // re-adds everything, regardless of whether it has a page action. For a |
702 // page action, browser action bounds do not change, as a result of which | 729 // page action, browser action bounds do not change, as a result of which |
703 // SetBounds does not do a layout at all. | 730 // SetBounds does not do a layout at all. |
704 // TODO(sidchat): Rework the above behavior so that explicit layout is not | 731 // TODO(sidchat): Rework the above behavior so that explicit layout is not |
705 // required. | 732 // required. |
706 browser_actions_->Layout(); | 733 browser_actions_->Layout(); |
| 734 Debug(browser_actions_->bounds(), L"BrowserAction"); |
707 | 735 |
708 // Extend the app menu to the screen's right edge in maximized mode just like | 736 // Extend the app menu to the screen's right edge in maximized mode just like |
709 // we extend the back button to the left edge. | 737 // we extend the back button to the left edge. |
710 if (maximized) | 738 if (maximized) |
711 app_menu_width += kRightEdgeSpacing; | 739 app_menu_width += kRightEdgeSpacing; |
712 app_menu_->SetBounds(browser_actions_->x() + browser_actions_width, child_y, | 740 app_menu_->SetBounds((browser_actions_->x() + browser_actions_width), scale *
child_y - 15, |
713 app_menu_width, child_height); | 741 wscale * app_menu_width, scale * child_height); |
| 742 Debug(app_menu_->bounds(), L"app_menu_"); |
714 } | 743 } |
715 | 744 |
716 bool ToolbarView::HitTestRect(const gfx::Rect& rect) const { | 745 bool ToolbarView::HitTestRect(const gfx::Rect& rect) const { |
717 // Don't take hits in our top shadow edge. Let them fall through to the | 746 // Don't take hits in our top shadow edge. Let them fall through to the |
718 // tab strip above us. | 747 // tab strip above us. |
719 if (rect.y() < content_shadow_height()) | 748 if (rect.y() < content_shadow_height()) |
720 return false; | 749 return false; |
721 // Otherwise let our superclass take care of it. | 750 // Otherwise let our superclass take care of it. |
722 return AccessiblePaneView::HitTestRect(rect); | 751 return AccessiblePaneView::HitTestRect(rect); |
723 } | 752 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 | 931 |
903 void ToolbarView::OnShowHomeButtonChanged() { | 932 void ToolbarView::OnShowHomeButtonChanged() { |
904 Layout(); | 933 Layout(); |
905 SchedulePaint(); | 934 SchedulePaint(); |
906 } | 935 } |
907 | 936 |
908 int ToolbarView::content_shadow_height() const { | 937 int ToolbarView::content_shadow_height() const { |
909 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? | 938 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? |
910 kContentShadowHeightAsh : kContentShadowHeight; | 939 kContentShadowHeightAsh : kContentShadowHeight; |
911 } | 940 } |
OLD | NEW |