Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/opaque_browser_frame_view_layout.h" | 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 7 #include "chrome/browser/profiles/profiles_state.h" | 8 #include "chrome/browser/profiles/profiles_state.h" |
| 8 #include "chrome/browser/ui/views/avatar_menu_button.h" | 9 #include "chrome/browser/ui/views/avatar_menu_button.h" |
| 10 #include "chrome/common/chrome_switches.h" | |
| 9 #include "ui/gfx/font.h" | 11 #include "ui/gfx/font.h" |
| 10 #include "ui/views/controls/button/image_button.h" | 12 #include "ui/views/controls/button/image_button.h" |
| 11 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
| 12 | 14 |
| 13 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
| 14 #include "win8/util/win8_util.h" | 16 #include "win8/util/win8_util.h" |
| 15 #endif // OS_WIN | 17 #endif // OS_WIN |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 137 |
| 136 gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip( | 138 gfx::Rect OpaqueBrowserFrameViewLayout::GetBoundsForTabStrip( |
| 137 const gfx::Size& tabstrip_preferred_size, | 139 const gfx::Size& tabstrip_preferred_size, |
| 138 int available_width) const { | 140 int available_width) const { |
| 139 available_width -= trailing_button_start_; | 141 available_width -= trailing_button_start_; |
| 140 available_width -= leading_button_start_; | 142 available_width -= leading_button_start_; |
| 141 | 143 |
| 142 if (delegate_->GetAdditionalReservedSpaceInTabStrip()) | 144 if (delegate_->GetAdditionalReservedSpaceInTabStrip()) |
| 143 available_width -= delegate_->GetAdditionalReservedSpaceInTabStrip(); | 145 available_width -= delegate_->GetAdditionalReservedSpaceInTabStrip(); |
| 144 | 146 |
| 145 const int caption_spacing = delegate_->IsMaximized() ? | 147 const int caption_spacing = IsTitleBarCondensed() ? |
| 146 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing; | 148 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing; |
| 147 const int tabstrip_width = available_width - caption_spacing; | 149 const int tabstrip_width = available_width - caption_spacing; |
| 148 gfx::Rect bounds(leading_button_start_, GetTabStripInsetsTop(false), | 150 gfx::Rect bounds(leading_button_start_, GetTabStripInsetsTop(false), |
| 149 std::max(0, tabstrip_width), | 151 std::max(0, tabstrip_width), |
| 150 tabstrip_preferred_size.height()); | 152 tabstrip_preferred_size.height()); |
| 151 | 153 |
| 152 int leading_tabstrip_indent = kTabStripIndent; | 154 int leading_tabstrip_indent = kTabStripIndent; |
| 153 if (delegate_->ShouldShowAvatar() && !ShouldAvatarBeOnRight()) { | 155 if (delegate_->ShouldShowAvatar() && !ShouldAvatarBeOnRight()) { |
| 154 if (avatar_label_ && avatar_label_->bounds().width()) | 156 if (avatar_label_ && avatar_label_->bounds().width()) |
| 155 leading_tabstrip_indent += kAvatarLabelInnerSpacing; | 157 leading_tabstrip_indent += kAvatarLabelInnerSpacing; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 168 NonClientTopBorderHeight(false) + border_thickness); | 170 NonClientTopBorderHeight(false) + border_thickness); |
| 169 | 171 |
| 170 // Ensure that we can, at minimum, hold our window controls and avatar icon. | 172 // Ensure that we can, at minimum, hold our window controls and avatar icon. |
| 171 min_size.set_width(std::max(min_size.width(), minimum_size_for_buttons_)); | 173 min_size.set_width(std::max(min_size.width(), minimum_size_for_buttons_)); |
| 172 | 174 |
| 173 // Ensure that the minimum width is enough to hold a minimum width tab strip | 175 // Ensure that the minimum width is enough to hold a minimum width tab strip |
| 174 // at its usual insets. | 176 // at its usual insets. |
| 175 if (delegate_->IsTabStripVisible()) { | 177 if (delegate_->IsTabStripVisible()) { |
| 176 gfx::Size preferred_size = delegate_->GetTabstripPreferredSize(); | 178 gfx::Size preferred_size = delegate_->GetTabstripPreferredSize(); |
| 177 const int min_tabstrip_width = preferred_size.width(); | 179 const int min_tabstrip_width = preferred_size.width(); |
| 178 const int caption_spacing = delegate_->IsMaximized() ? | 180 const int caption_spacing = IsTitleBarCondensed() ? |
| 179 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing; | 181 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing; |
| 180 min_size.Enlarge(min_tabstrip_width + caption_spacing, 0); | 182 min_size.Enlarge(min_tabstrip_width + caption_spacing, 0); |
| 181 } | 183 } |
| 182 | 184 |
| 183 return min_size; | 185 return min_size; |
| 184 } | 186 } |
| 185 | 187 |
| 186 gfx::Rect OpaqueBrowserFrameViewLayout::GetWindowBoundsForClientBounds( | 188 gfx::Rect OpaqueBrowserFrameViewLayout::GetWindowBoundsForClientBounds( |
| 187 const gfx::Rect& client_bounds) const { | 189 const gfx::Rect& client_bounds) const { |
| 188 int top_height = NonClientTopBorderHeight(false); | 190 int top_height = NonClientTopBorderHeight(false); |
| 189 int border_thickness = NonClientBorderThickness(); | 191 int border_thickness = NonClientBorderThickness(); |
| 190 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), | 192 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness), |
| 191 std::max(0, client_bounds.y() - top_height), | 193 std::max(0, client_bounds.y() - top_height), |
| 192 client_bounds.width() + (2 * border_thickness), | 194 client_bounds.width() + (2 * border_thickness), |
| 193 client_bounds.height() + top_height + border_thickness); | 195 client_bounds.height() + top_height + border_thickness); |
| 194 } | 196 } |
| 195 | 197 |
| 196 int OpaqueBrowserFrameViewLayout::FrameBorderThickness(bool restored) const { | 198 int OpaqueBrowserFrameViewLayout::FrameBorderThickness(bool restored) const { |
| 197 return (!restored && (delegate_->IsMaximized() || | 199 return (!restored && (IsTitleBarCondensed() || |
| 198 delegate_->IsFullscreen())) ? | 200 delegate_->IsFullscreen())) ? |
| 199 0 : kFrameBorderThickness; | 201 0 : kFrameBorderThickness; |
| 200 } | 202 } |
| 201 | 203 |
| 202 int OpaqueBrowserFrameViewLayout::NonClientBorderThickness() const { | 204 int OpaqueBrowserFrameViewLayout::NonClientBorderThickness() const { |
| 203 // When we fill the screen, we don't show a client edge. | 205 // When we fill the screen, we don't show a client edge. |
| 204 return FrameBorderThickness(false) + | 206 return FrameBorderThickness(false) + |
| 205 ((delegate_->IsMaximized() || delegate_->IsFullscreen()) ? | 207 ((IsTitleBarCondensed() || delegate_->IsFullscreen()) ? |
| 206 0 : views::NonClientFrameView::kClientEdgeThickness); | 208 0 : views::NonClientFrameView::kClientEdgeThickness); |
| 207 } | 209 } |
| 208 | 210 |
| 209 int OpaqueBrowserFrameViewLayout::NonClientTopBorderHeight( | 211 int OpaqueBrowserFrameViewLayout::NonClientTopBorderHeight( |
| 210 bool restored) const { | 212 bool restored) const { |
| 211 if (delegate_->ShouldShowWindowTitle()) { | 213 if (delegate_->ShouldShowWindowTitle()) { |
| 212 return std::max(FrameBorderThickness(restored) + delegate_->GetIconSize(), | 214 return std::max(FrameBorderThickness(restored) + delegate_->GetIconSize(), |
| 213 CaptionButtonY(restored) + kCaptionButtonHeightWithPadding) + | 215 CaptionButtonY(restored) + kCaptionButtonHeightWithPadding) + |
| 214 TitlebarBottomThickness(restored); | 216 TitlebarBottomThickness(restored); |
| 215 } | 217 } |
| 216 | 218 |
| 217 return FrameBorderThickness(restored) - | 219 return FrameBorderThickness(restored) - |
| 218 ((delegate_->IsTabStripVisible() && | 220 ((delegate_->IsTabStripVisible() && !restored && |
| 219 !restored && !delegate_->ShouldLeaveOffsetNearTopBorder()) | 221 (!delegate_->ShouldLeaveOffsetNearTopBorder() || |
|
James Cook
2013/12/19 20:57:55
Though not your fault, this conditional is too cra
Matt Giuca
2013/12/20 03:53:22
Done.
| |
| 220 ? kTabstripTopShadowThickness : 0); | 222 IsTitleBarCondensed())) |
| 223 ? kTabstripTopShadowThickness | |
| 224 : 0); | |
| 221 } | 225 } |
| 222 | 226 |
| 223 int OpaqueBrowserFrameViewLayout::GetTabStripInsetsTop(bool restored) const { | 227 int OpaqueBrowserFrameViewLayout::GetTabStripInsetsTop(bool restored) const { |
| 224 return NonClientTopBorderHeight(restored) + ((!restored && | 228 return NonClientTopBorderHeight(restored) + ((!restored && |
| 225 (!delegate_->ShouldLeaveOffsetNearTopBorder() || | 229 (!delegate_->ShouldLeaveOffsetNearTopBorder() || |
| 230 IsTitleBarCondensed() || | |
| 226 delegate_->IsFullscreen())) ? | 231 delegate_->IsFullscreen())) ? |
| 227 0 : kNonClientRestoredExtraThickness); | 232 0 : kNonClientRestoredExtraThickness); |
| 228 } | 233 } |
| 229 | 234 |
| 230 int OpaqueBrowserFrameViewLayout::TitlebarBottomThickness(bool restored) const { | 235 int OpaqueBrowserFrameViewLayout::TitlebarBottomThickness(bool restored) const { |
| 231 return kTitlebarTopAndBottomEdgeThickness + | 236 return kTitlebarTopAndBottomEdgeThickness + |
| 232 ((!restored && delegate_->IsMaximized()) ? 0 : | 237 ((!restored && IsTitleBarCondensed()) ? 0 : |
| 233 views::NonClientFrameView::kClientEdgeThickness); | 238 views::NonClientFrameView::kClientEdgeThickness); |
| 234 } | 239 } |
| 235 | 240 |
| 236 int OpaqueBrowserFrameViewLayout::CaptionButtonY(bool restored) const { | 241 int OpaqueBrowserFrameViewLayout::CaptionButtonY(bool restored) const { |
| 237 // Maximized buttons start at window top, since the window has no border. This | 242 // Maximized buttons start at window top, since the window has no border. This |
| 238 // offset is for the image (the actual clickable bounds extend all the way to | 243 // offset is for the image (the actual clickable bounds extend all the way to |
| 239 // the top to take Fitts' Law into account). | 244 // the top to take Fitts' Law into account). |
| 240 return ((!restored && delegate_->IsMaximized()) ? | 245 return ((!restored && IsTitleBarCondensed()) ? |
| 241 FrameBorderThickness(false) : | 246 FrameBorderThickness(false) : |
| 242 views::NonClientFrameView::kFrameShadowThickness) + extra_caption_y_; | 247 views::NonClientFrameView::kFrameShadowThickness) + extra_caption_y_; |
| 243 } | 248 } |
| 244 | 249 |
| 245 gfx::Rect OpaqueBrowserFrameViewLayout::IconBounds() const { | 250 gfx::Rect OpaqueBrowserFrameViewLayout::IconBounds() const { |
| 246 return window_icon_bounds_; | 251 return window_icon_bounds_; |
| 247 } | 252 } |
| 248 | 253 |
| 249 gfx::Rect OpaqueBrowserFrameViewLayout::CalculateClientAreaBounds( | 254 gfx::Rect OpaqueBrowserFrameViewLayout::CalculateClientAreaBounds( |
| 250 int width, | 255 int width, |
| 251 int height) const { | 256 int height) const { |
| 252 int top_height = NonClientTopBorderHeight(false); | 257 int top_height = NonClientTopBorderHeight(false); |
| 253 int border_thickness = NonClientBorderThickness(); | 258 int border_thickness = NonClientBorderThickness(); |
| 254 return gfx::Rect(border_thickness, top_height, | 259 return gfx::Rect(border_thickness, top_height, |
| 255 std::max(0, width - (2 * border_thickness)), | 260 std::max(0, width - (2 * border_thickness)), |
| 256 std::max(0, height - top_height - border_thickness)); | 261 std::max(0, height - top_height - border_thickness)); |
| 257 } | 262 } |
| 258 | 263 |
| 264 bool OpaqueBrowserFrameViewLayout::IsTitleBarCondensed() const { | |
| 265 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 266 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseSystemTitleBar)) | |
| 267 return true; | |
| 268 #endif | |
| 269 | |
| 270 return delegate_->IsMaximized(); | |
| 271 } | |
| 272 | |
| 259 /////////////////////////////////////////////////////////////////////////////// | 273 /////////////////////////////////////////////////////////////////////////////// |
| 260 // OpaqueBrowserFrameView, private: | 274 // OpaqueBrowserFrameView, private: |
| 261 | 275 |
| 262 bool OpaqueBrowserFrameViewLayout::ShouldAvatarBeOnRight() const { | 276 bool OpaqueBrowserFrameViewLayout::ShouldAvatarBeOnRight() const { |
| 263 // The avatar should be shown either on the end of the left or the beginning | 277 // The avatar should be shown either on the end of the left or the beginning |
| 264 // of the right depending on which side has fewer buttons. | 278 // of the right depending on which side has fewer buttons. |
| 265 return trailing_buttons_.size() < leading_buttons_.size(); | 279 return trailing_buttons_.size() < leading_buttons_.size(); |
| 266 } | 280 } |
| 267 | 281 |
| 268 void OpaqueBrowserFrameViewLayout::LayoutWindowControls(views::View* host) { | 282 void OpaqueBrowserFrameViewLayout::LayoutWindowControls(views::View* host) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 use_hidden_icon_location = false; | 327 use_hidden_icon_location = false; |
| 314 | 328 |
| 315 // Our frame border has a different "3D look" than Windows'. Theirs has | 329 // Our frame border has a different "3D look" than Windows'. Theirs has |
| 316 // a more complex gradient on the top that they push their icon/title | 330 // a more complex gradient on the top that they push their icon/title |
| 317 // below; then the maximized window cuts this off and the icon/title are | 331 // below; then the maximized window cuts this off and the icon/title are |
| 318 // centered in the remaining space. Because the apparent shape of our | 332 // centered in the remaining space. Because the apparent shape of our |
| 319 // border is simpler, using the same positioning makes things look | 333 // border is simpler, using the same positioning makes things look |
| 320 // slightly uncentered with restored windows, so when the window is | 334 // slightly uncentered with restored windows, so when the window is |
| 321 // restored, instead of calculating the remaining space from below the | 335 // restored, instead of calculating the remaining space from below the |
| 322 // frame border, we calculate from below the 3D edge. | 336 // frame border, we calculate from below the 3D edge. |
| 323 int unavailable_px_at_top = delegate_->IsMaximized() ? | 337 int unavailable_px_at_top = IsTitleBarCondensed() ? |
| 324 frame_thickness : kTitlebarTopAndBottomEdgeThickness; | 338 frame_thickness : kTitlebarTopAndBottomEdgeThickness; |
| 325 // When the icon is shorter than the minimum space we reserve for the | 339 // When the icon is shorter than the minimum space we reserve for the |
| 326 // caption button, we vertically center it. We want to bias rounding to | 340 // caption button, we vertically center it. We want to bias rounding to |
| 327 // put extra space above the icon, since the 3D edge (+ client edge, for | 341 // put extra space above the icon, since the 3D edge (+ client edge, for |
| 328 // restored windows) below looks (to the eye) more like additional space | 342 // restored windows) below looks (to the eye) more like additional space |
| 329 // than does the 3D edge (or nothing at all, for maximized windows) | 343 // than does the 3D edge (or nothing at all, for maximized windows) |
| 330 // above; hence the +1. | 344 // above; hence the +1. |
| 331 int y = unavailable_px_at_top + (NonClientTopBorderHeight(false) - | 345 int y = unavailable_px_at_top + (NonClientTopBorderHeight(false) - |
| 332 unavailable_px_at_top - size - | 346 unavailable_px_at_top - size - |
| 333 TitlebarBottomThickness(false) + 1) / 2; | 347 TitlebarBottomThickness(false) + 1) / 2; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); | 413 gfx::ImageSkia incognito_icon = delegate_->GetOTRAvatarIcon(); |
| 400 | 414 |
| 401 bool avatar_on_right = ShouldAvatarBeOnRight(); | 415 bool avatar_on_right = ShouldAvatarBeOnRight(); |
| 402 int avatar_bottom = GetTabStripInsetsTop(false) + | 416 int avatar_bottom = GetTabStripInsetsTop(false) + |
| 403 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; | 417 delegate_->GetTabStripHeight() - kAvatarBottomSpacing; |
| 404 int avatar_restored_y = avatar_bottom - incognito_icon.height(); | 418 int avatar_restored_y = avatar_bottom - incognito_icon.height(); |
| 405 int avatar_x = avatar_on_right ? | 419 int avatar_x = avatar_on_right ? |
| 406 host->width() - trailing_button_start_ - kAvatarOuterSpacing - | 420 host->width() - trailing_button_start_ - kAvatarOuterSpacing - |
| 407 incognito_icon.width() : | 421 incognito_icon.width() : |
| 408 leading_button_start_ + kAvatarOuterSpacing; | 422 leading_button_start_ + kAvatarOuterSpacing; |
| 409 int avatar_y = delegate_->IsMaximized() ? | 423 int avatar_y = IsTitleBarCondensed() ? |
| 410 (NonClientTopBorderHeight(false) + kTabstripTopShadowThickness) : | 424 (NonClientTopBorderHeight(false) + kTabstripTopShadowThickness) : |
| 411 avatar_restored_y; | 425 avatar_restored_y; |
| 412 avatar_bounds_.SetRect( | 426 avatar_bounds_.SetRect( |
| 413 avatar_x, | 427 avatar_x, |
| 414 avatar_y, | 428 avatar_y, |
| 415 incognito_icon.width(), | 429 incognito_icon.width(), |
| 416 delegate_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); | 430 delegate_->ShouldShowAvatar() ? (avatar_bottom - avatar_y) : 0); |
| 417 if (avatar_button_) { | 431 if (avatar_button_) { |
| 418 avatar_button_->set_button_on_right(avatar_on_right); | 432 avatar_button_->set_button_on_right(avatar_on_right); |
| 419 avatar_button_->SetBoundsRect(avatar_bounds_); | 433 avatar_button_->SetBoundsRect(avatar_bounds_); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 | 519 |
| 506 button->SetImageAlignment( | 520 button->SetImageAlignment( |
| 507 (alignment == ALIGN_LEADING) ? | 521 (alignment == ALIGN_LEADING) ? |
| 508 views::ImageButton::ALIGN_RIGHT : views::ImageButton::ALIGN_LEFT, | 522 views::ImageButton::ALIGN_RIGHT : views::ImageButton::ALIGN_LEFT, |
| 509 views::ImageButton::ALIGN_BOTTOM); | 523 views::ImageButton::ALIGN_BOTTOM); |
| 510 | 524 |
| 511 // There should always be the same number of non-shadow pixels visible to the | 525 // There should always be the same number of non-shadow pixels visible to the |
| 512 // side of the caption buttons. In maximized mode we extend buttons to the | 526 // side of the caption buttons. In maximized mode we extend buttons to the |
| 513 // screen top and the rightmost button to the screen right (or leftmost button | 527 // screen top and the rightmost button to the screen right (or leftmost button |
| 514 // to the screen left, for left-aligned buttons) to obey Fitts' Law. | 528 // to the screen left, for left-aligned buttons) to obey Fitts' Law. |
| 515 bool is_maximized = delegate_->IsMaximized(); | 529 bool is_maximized = IsTitleBarCondensed(); |
|
James Cook
2013/12/19 20:57:55
nit: Maybe call this title_bar_condensed instead o
Matt Giuca
2013/12/20 03:53:22
Done.
| |
| 516 | 530 |
| 517 // When we are the first button on the leading side and are the close | 531 // When we are the first button on the leading side and are the close |
| 518 // button, we must flip ourselves, because the close button assets have | 532 // button, we must flip ourselves, because the close button assets have |
| 519 // a little notch to fit in the rounded frame. | 533 // a little notch to fit in the rounded frame. |
| 520 button->SetDrawImageMirrored(alignment == ALIGN_LEADING && | 534 button->SetDrawImageMirrored(alignment == ALIGN_LEADING && |
| 521 !has_leading_buttons_ && | 535 !has_leading_buttons_ && |
| 522 button == close_button_); | 536 button == close_button_); |
| 523 // If the window is maximized, align the buttons to its upper edge. | 537 // If the window is maximized, align the buttons to its upper edge. |
| 524 int extra_height = is_maximized ? extra_caption_y_ : 0; | 538 int extra_height = is_maximized ? extra_caption_y_ : 0; |
| 525 | 539 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 | 686 |
| 673 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, | 687 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, |
| 674 views::View* view) { | 688 views::View* view) { |
| 675 SetView(view->id(), view); | 689 SetView(view->id(), view); |
| 676 } | 690 } |
| 677 | 691 |
| 678 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, | 692 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, |
| 679 views::View* view) { | 693 views::View* view) { |
| 680 SetView(view->id(), NULL); | 694 SetView(view->id(), NULL); |
| 681 } | 695 } |
| OLD | NEW |