Index: chrome/browser/ui/views/toolbar_view.cc |
diff --git a/chrome/browser/ui/views/toolbar_view.cc b/chrome/browser/ui/views/toolbar_view.cc |
index b74a9b5846280dade413f247ea897317d1ec65dc..d57fb66f582abd2936ff9656958a178617d82758 100644 |
--- a/chrome/browser/ui/views/toolbar_view.cc |
+++ b/chrome/browser/ui/views/toolbar_view.cc |
@@ -604,10 +604,21 @@ bool ToolbarView::GetAcceleratorForCommandId(int command_id, |
return GetWidget()->GetAccelerator(command_id, accelerator); |
} |
+float GetScaleFactor() { |
+ switch (ui::GetMaxScaleFactor()) { |
+ case ui::SCALE_FACTOR_140P: |
+ return 1.4f; |
+ case ui::SCALE_FACTOR_180P: |
+ return 1.8f; |
+ } |
+ return 1.0f; |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// ToolbarView, views::View overrides: |
gfx::Size ToolbarView::GetPreferredSize() { |
+ float scale = 1; // GetScaleFactor(); |
if (is_display_mode_normal()) { |
int min_width = kLeftEdgeSpacing + |
back_->GetPreferredSize().width() + kButtonSpacing + |
@@ -620,15 +631,20 @@ gfx::Size ToolbarView::GetPreferredSize() { |
app_menu_->GetPreferredSize().width() + kRightEdgeSpacing; |
gfx::ImageSkia* normal_background = |
GetThemeProvider()->GetImageSkiaNamed(IDR_CONTENT_TOP_CENTER); |
- return gfx::Size(min_width, |
- normal_background->height() - content_shadow_height()); |
+ return gfx::Size(min_width * scale, |
+ (normal_background->height() - kContentShadowHeight) * scale); |
} |
int vertical_spacing = PopupTopSpacing() + |
(GetWidget()->ShouldUseNativeFrame() ? |
kPopupBottomSpacingGlass : kPopupBottomSpacingNonGlass); |
- return gfx::Size(0, location_bar_->GetPreferredSize().height() + |
- vertical_spacing); |
+ return gfx::Size(0, (location_bar_->GetPreferredSize().height() + |
+ vertical_spacing) * scale); |
+} |
+ |
+#include "/gtools.h" |
+void Debug(const gfx::Rect& bounds, LPCTSTR message) { |
+ Debug(L"%s (%d, %d, %d, %d)", message, bounds.x(), bounds.y(), bounds.width(), bounds.height()); |
} |
void ToolbarView::Layout() { |
@@ -636,6 +652,8 @@ void ToolbarView::Layout() { |
if (back_ == NULL) |
return; |
+ // Layout is done in screen (non-dip) pixels. |
+ |
bool maximized = browser_->window() && browser_->window()->IsMaximized(); |
if (!is_display_mode_normal()) { |
int edge_width = maximized ? |
@@ -644,10 +662,14 @@ void ToolbarView::Layout() { |
width() - (edge_width * 2), location_bar_->GetPreferredSize().height()); |
return; |
} |
+ float scale = GetScaleFactor(); |
+ float wscale = scale;// = 1; |
+ Debug(back_->bounds(), L"Original back"); |
+ Debug(this->bounds(), L"This bounds"); |
// We assume all child elements are the same height. |
int child_height = |
- std::min(back_->GetPreferredSize().height(), height()); |
+ std::min((int)(scale * back_->GetPreferredSize().height()), height()); |
// Set child_y such that buttons appear vertically centered. To preseve |
// the behaviour on non-touch UIs, round-up by taking |
@@ -664,38 +686,43 @@ void ToolbarView::Layout() { |
// http://crbug.com/5540 |
int back_width = back_->GetPreferredSize().width(); |
if (maximized) |
- back_->SetBounds(0, child_y, back_width + kLeftEdgeSpacing, child_height); |
+ back_->SetBounds(0, scale * child_y, scale * (back_width + kLeftEdgeSpacing), scale * child_height); |
else |
- back_->SetBounds(kLeftEdgeSpacing, child_y, back_width, child_height); |
- |
- forward_->SetBounds(back_->x() + back_->width() + kButtonSpacing, |
- child_y, forward_->GetPreferredSize().width(), child_height); |
- |
- reload_->SetBounds(forward_->x() + forward_->width() + kButtonSpacing, |
- child_y, reload_->GetPreferredSize().width(), child_height); |
- |
+ back_->SetBounds(scale * kLeftEdgeSpacing, scale * child_y, wscale * back_width, scale * child_height); |
+ Debug(back_->bounds(), L"Back"); |
+ forward_->SetBounds((back_->x() + back_->width() + scale * kButtonSpacing), |
+ scale * child_y, wscale * forward_->GetPreferredSize().width(), scale * child_height); |
+ Debug(forward_->bounds(), L"Forward"); |
+ |
+ gfx::Size reloadSize = reload_->GetPreferredSize(); |
+ reload_->SetBounds((forward_->x() + forward_->width() + scale * kButtonSpacing), |
+ scale * child_y, wscale * reload_->GetPreferredSize().width(), scale * child_height); |
+ Debug(reload_->bounds(), L"Reload"); |
if (show_home_button_.GetValue()) { |
home_->SetVisible(true); |
- home_->SetBounds(reload_->x() + reload_->width() + kButtonSpacing, child_y, |
- home_->GetPreferredSize().width(), child_height); |
+ home_->SetBounds((reload_->x() + reload_->width() + scale * kButtonSpacing), scale * child_y, |
+ wscale * home_->GetPreferredSize().width(), scale * child_height); |
} else { |
home_->SetVisible(false); |
- home_->SetBounds(reload_->x() + reload_->width(), child_y, 0, child_height); |
+ home_->SetBounds(reload_->x() + reload_->width(), scale * child_y, 0, scale * child_height); |
} |
- |
+ Debug(home_->bounds(), L"Home"); |
int browser_actions_width = browser_actions_->GetPreferredSize().width(); |
int app_menu_width = app_menu_->GetPreferredSize().width(); |
- int location_x = home_->x() + home_->width() + kStandardSpacing; |
+ int location_x = home_->x() + home_->width() + scale * kStandardSpacing; |
int available_width = std::max(0, width() - kRightEdgeSpacing - |
- app_menu_width - browser_actions_width - location_x); |
+ app_menu_width - (int)(scale * browser_actions_width) - location_x); |
- int location_y = std::min(location_bar_vert_spacing(), height()); |
+ int location_y = scale * std::min(location_bar_vert_spacing(), height()); |
int location_bar_height = location_bar_->GetPreferredSize().height(); |
+ location_bar_height = child_height; |
location_bar_->SetBounds(location_x, location_y, std::max(available_width, 0), |
- location_bar_height); |
+ scale * location_bar_height); |
- browser_actions_->SetBounds(location_bar_->x() + location_bar_->width(), 0, |
- browser_actions_width, height()); |
+ Debug(location_bar_->bounds(), L"LocationBar"); |
+ browser_actions_->SetBounds((location_bar_->x() + location_bar_->width()), 0, |
+ wscale * browser_actions_width, /*scale **/ height()); |
+ Debug(browser_actions_->bounds(), L"BrowserAction"); |
// The browser actions need to do a layout explicitly, because when an |
// extension is loaded/unloaded/changed, BrowserActionContainer removes and |
// re-adds everything, regardless of whether it has a page action. For a |
@@ -704,13 +731,15 @@ void ToolbarView::Layout() { |
// TODO(sidchat): Rework the above behavior so that explicit layout is not |
// required. |
browser_actions_->Layout(); |
+ Debug(browser_actions_->bounds(), L"BrowserAction"); |
// Extend the app menu to the screen's right edge in maximized mode just like |
// we extend the back button to the left edge. |
if (maximized) |
app_menu_width += kRightEdgeSpacing; |
- app_menu_->SetBounds(browser_actions_->x() + browser_actions_width, child_y, |
- app_menu_width, child_height); |
+ app_menu_->SetBounds((browser_actions_->x() + browser_actions_width), scale * child_y - 15, |
+ wscale * app_menu_width, scale * child_height); |
+ Debug(app_menu_->bounds(), L"app_menu_"); |
} |
bool ToolbarView::HitTestRect(const gfx::Rect& rect) const { |