| 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 "base/command_line.h" |
| 8 #include "base/containers/adapters.h" | 8 #include "base/containers/adapters.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/profiles/profiles_state.h" | 10 #include "chrome/browser/profiles/profiles_state.h" |
| 11 #include "chrome/browser/ui/layout_constants.h" | 11 #include "chrome/browser/ui/layout_constants.h" |
| 12 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" | 12 #include "chrome/browser/ui/views/profiles/profile_indicator_icon.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "components/signin/core/common/profile_management_switches.h" | 14 #include "components/signin/core/common/profile_management_switches.h" |
| 15 #include "ui/base/material_design/material_design_controller.h" | |
| 16 #include "ui/gfx/font.h" | 15 #include "ui/gfx/font.h" |
| 17 #include "ui/views/controls/button/image_button.h" | 16 #include "ui/views/controls/button/image_button.h" |
| 18 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 const int kCaptionButtonHeight = 18; | 21 const int kCaptionButtonHeight = 18; |
| 23 | 22 |
| 24 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 23 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 25 // Default extra space between the top of the frame and the top of the window | 24 // Default extra space between the top of the frame and the top of the window |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // The tab top inset is equal to the height of any shadow region above the | 172 // The tab top inset is equal to the height of any shadow region above the |
| 174 // tabs, plus a 1 px top stroke. In maximized mode, we want to push the | 173 // tabs, plus a 1 px top stroke. In maximized mode, we want to push the |
| 175 // shadow region off the top of the screen but leave the top stroke. | 174 // shadow region off the top of the screen but leave the top stroke. |
| 176 if (!restored && delegate_->IsTabStripVisible() && IsTitleBarCondensed()) | 175 if (!restored && delegate_->IsTabStripVisible() && IsTitleBarCondensed()) |
| 177 thickness -= GetLayoutInsets(TAB).top() - 1; | 176 thickness -= GetLayoutInsets(TAB).top() - 1; |
| 178 return thickness; | 177 return thickness; |
| 179 } | 178 } |
| 180 | 179 |
| 181 int OpaqueBrowserFrameViewLayout::GetTabStripInsetsTop(bool restored) const { | 180 int OpaqueBrowserFrameViewLayout::GetTabStripInsetsTop(bool restored) const { |
| 182 const int top = NonClientTopHeight(restored); | 181 const int top = NonClientTopHeight(restored); |
| 183 // Annoyingly, the pre-MD layout uses different heights for the hit-test | 182 return (!restored && (IsTitleBarCondensed() || delegate_->IsFullscreen())) |
| 184 // exclusion region (which we want here, since we're trying to size the border | 183 ? top |
| 185 // so that the region above the tab's hit-test zone matches) versus the shadow | 184 : (top + kNonClientRestoredExtraThickness); |
| 186 // thickness. | |
| 187 const int exclusion = GetLayoutConstant(TAB_TOP_EXCLUSION_HEIGHT); | |
| 188 return (!restored && (IsTitleBarCondensed() || delegate_->IsFullscreen())) ? | |
| 189 top : (top + kNonClientRestoredExtraThickness - exclusion); | |
| 190 } | 185 } |
| 191 | 186 |
| 192 int OpaqueBrowserFrameViewLayout::TitlebarTopThickness(bool restored) const { | 187 int OpaqueBrowserFrameViewLayout::TitlebarTopThickness(bool restored) const { |
| 193 return (restored || !IsTitleBarCondensed()) ? | 188 return (restored || !IsTitleBarCondensed()) ? |
| 194 kTitlebarTopEdgeThickness : FrameBorderThickness(false); | 189 kTitlebarTopEdgeThickness : FrameBorderThickness(false); |
| 195 } | 190 } |
| 196 | 191 |
| 197 int OpaqueBrowserFrameViewLayout::CaptionButtonY(bool restored) const { | 192 int OpaqueBrowserFrameViewLayout::CaptionButtonY(bool restored) const { |
| 198 // Maximized buttons start at window top, since the window has no border. This | 193 // Maximized buttons start at window top, since the window has no border. This |
| 199 // offset is for the image (the actual clickable bounds extend all the way to | 194 // offset is for the image (the actual clickable bounds extend all the way to |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 new_avatar_button_->SetBounds(button_x, button_y, button_width, | 356 new_avatar_button_->SetBounds(button_x, button_y, button_width, |
| 362 kCaptionButtonHeight); | 357 kCaptionButtonHeight); |
| 363 } | 358 } |
| 364 | 359 |
| 365 void OpaqueBrowserFrameViewLayout::LayoutIncognitoIcon(views::View* host) { | 360 void OpaqueBrowserFrameViewLayout::LayoutIncognitoIcon(views::View* host) { |
| 366 const int old_button_size = leading_button_start_ + trailing_button_start_; | 361 const int old_button_size = leading_button_start_ + trailing_button_start_; |
| 367 | 362 |
| 368 // Any buttons/icon/title were laid out based on the frame border thickness, | 363 // Any buttons/icon/title were laid out based on the frame border thickness, |
| 369 // but the tabstrip bounds need to be based on the non-client border thickness | 364 // but the tabstrip bounds need to be based on the non-client border thickness |
| 370 // on any side where there aren't other buttons forcing a larger inset. | 365 // on any side where there aren't other buttons forcing a larger inset. |
| 371 const bool md = ui::MaterialDesignController::IsModeMaterial(); | |
| 372 int min_button_width = NonClientBorderThickness(); | 366 int min_button_width = NonClientBorderThickness(); |
| 373 // In non-MD, the toolbar has a rounded corner that we don't want the tabstrip | |
| 374 // to overlap. | |
| 375 if (!md && !incognito_icon_ && delegate_->IsToolbarVisible()) | |
| 376 min_button_width += delegate_->GetToolbarLeadingCornerClientWidth(); | |
| 377 leading_button_start_ = std::max(leading_button_start_, min_button_width); | 367 leading_button_start_ = std::max(leading_button_start_, min_button_width); |
| 378 // The trailing corner is a mirror of the leading one. | 368 // The trailing corner is a mirror of the leading one. |
| 379 trailing_button_start_ = std::max(trailing_button_start_, min_button_width); | 369 trailing_button_start_ = std::max(trailing_button_start_, min_button_width); |
| 380 | 370 |
| 381 if (incognito_icon_) { | 371 if (incognito_icon_) { |
| 382 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); | 372 const gfx::Insets insets(GetLayoutInsets(AVATAR_ICON)); |
| 383 const gfx::Size size(delegate_->GetIncognitoAvatarIcon().size()); | 373 const gfx::Size size(delegate_->GetIncognitoAvatarIcon().size()); |
| 384 const int incognito_width = insets.left() + size.width(); | 374 const int incognito_width = insets.left() + size.width(); |
| 385 int x; | 375 int x; |
| 386 if (ShouldIncognitoIconBeOnRight()) { | 376 if (ShouldIncognitoIconBeOnRight()) { |
| 387 trailing_button_start_ += incognito_width; | 377 trailing_button_start_ += incognito_width; |
| 388 x = host->width() - trailing_button_start_; | 378 x = host->width() - trailing_button_start_; |
| 389 } else { | 379 } else { |
| 390 x = leading_button_start_ + insets.left(); | 380 x = leading_button_start_ + insets.left(); |
| 391 leading_button_start_ += incognito_width; | 381 leading_button_start_ += incognito_width; |
| 392 } | 382 } |
| 393 const int bottom = GetTabStripInsetsTop(false) + | 383 const int bottom = GetTabStripInsetsTop(false) + |
| 394 delegate_->GetTabStripHeight() - insets.bottom(); | 384 delegate_->GetTabStripHeight() - insets.bottom(); |
| 395 const int y = (md || !IsTitleBarCondensed()) ? | 385 incognito_icon_->SetBounds(x, bottom - size.height(), size.width(), |
| 396 (bottom - size.height()) : FrameBorderThickness(false); | 386 size.height()); |
| 397 incognito_icon_->SetBounds(x, y, size.width(), bottom - y); | |
| 398 } | 387 } |
| 399 | 388 |
| 400 minimum_size_for_buttons_ += | 389 minimum_size_for_buttons_ += |
| 401 (leading_button_start_ + trailing_button_start_ - old_button_size); | 390 (leading_button_start_ + trailing_button_start_ - old_button_size); |
| 402 } | 391 } |
| 403 | 392 |
| 404 void OpaqueBrowserFrameViewLayout::ConfigureButton( | 393 void OpaqueBrowserFrameViewLayout::ConfigureButton( |
| 405 views::View* host, | 394 views::View* host, |
| 406 views::FrameButton button_id, | 395 views::FrameButton button_id, |
| 407 ButtonAlignment alignment, | 396 ButtonAlignment alignment, |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 | 601 |
| 613 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, | 602 void OpaqueBrowserFrameViewLayout::ViewAdded(views::View* host, |
| 614 views::View* view) { | 603 views::View* view) { |
| 615 SetView(view->id(), view); | 604 SetView(view->id(), view); |
| 616 } | 605 } |
| 617 | 606 |
| 618 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, | 607 void OpaqueBrowserFrameViewLayout::ViewRemoved(views::View* host, |
| 619 views::View* view) { | 608 views::View* view) { |
| 620 SetView(view->id(), nullptr); | 609 SetView(view->id(), nullptr); |
| 621 } | 610 } |
| OLD | NEW |