Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/infobar_container_delegate.h" | 5 #include "chrome/browser/ui/infobar_container_delegate.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "ui/base/material_design/material_design_controller.h" | 8 #include "ui/base/material_design/material_design_controller.h" |
| 9 #include "ui/gfx/animation/slide_animation.h" | 9 #include "ui/gfx/animation/slide_animation.h" |
| 10 | 10 |
| 11 #if defined(TOOLKIT_VIEWS) | 11 #if defined(TOOLKIT_VIEWS) |
| 12 #include "ui/views/window/non_client_view.h" | 12 #include "ui/views/window/non_client_view.h" |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 namespace { | |
| 16 | |
| 17 int GetDefaultArrowTargetHeight() { | |
| 18 return ui::MaterialDesignController::IsModeMaterial() | |
| 19 ? InfoBarContainerDelegate::kDefaultArrowTargetHeightMd | |
| 20 : InfoBarContainerDelegate::kDefaultArrowTargetHeight; | |
| 21 } | |
| 22 | |
| 23 int GetDefaultArrowTargetHalfWidth() { | |
| 24 return ui::MaterialDesignController::IsModeMaterial() | |
| 25 ? InfoBarContainerDelegate::kDefaultArrowTargetHalfWidthMd | |
| 26 : InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth; | |
| 27 } | |
| 28 | |
| 29 int GetSeparatorLineHeightForLayout() { | |
| 30 return ui::MaterialDesignController::IsModeMaterial() | |
| 31 ? 0 | |
| 32 : InfoBarContainerDelegate::kSeparatorLineHeight; | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 15 // static | 37 // static |
| 16 #if defined(OS_MACOSX) | 38 #if defined(OS_MACOSX) |
| 17 const int InfoBarContainerDelegate::kSeparatorLineHeight = 1; | 39 const int InfoBarContainerDelegate::kSeparatorLineHeight = 1; |
| 18 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 11; | 40 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 11; |
| 41 const int InfoBarContainerDelegate::kDefaultArrowTargetHeightMd = 11; | |
| 19 #elif defined(TOOLKIT_VIEWS) | 42 #elif defined(TOOLKIT_VIEWS) |
| 20 // Views comes second until the Mac browser is Views-based. | 43 // Views comes second until the Mac browser is Views-based. |
| 21 const int InfoBarContainerDelegate::kSeparatorLineHeight = | 44 const int InfoBarContainerDelegate::kSeparatorLineHeight = |
| 22 views::NonClientFrameView::kClientEdgeThickness; | 45 views::NonClientFrameView::kClientEdgeThickness; |
| 23 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 9; | 46 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 9; |
| 47 const int InfoBarContainerDelegate::kDefaultArrowTargetHeightMd = 11; | |
| 24 #endif | 48 #endif |
| 25 | 49 |
| 26 const int InfoBarContainerDelegate::kDefaultBarTargetHeight = 36; | 50 const int InfoBarContainerDelegate::kDefaultBarTargetHeight = 36; |
| 27 const int InfoBarContainerDelegate::kDefaultBarTargetHeightMd = 40; | 51 const int InfoBarContainerDelegate::kDefaultBarTargetHeightMd = 40; |
| 28 const int InfoBarContainerDelegate::kMaximumArrowTargetHeight = 24; | 52 const int InfoBarContainerDelegate::kMaximumArrowTargetHeight = 24; |
| 29 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth = | 53 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth = |
| 30 kDefaultArrowTargetHeight; | 54 kDefaultArrowTargetHeight; |
| 55 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidthMd = | |
| 56 kDefaultArrowTargetHeightMd; | |
| 31 const int InfoBarContainerDelegate::kMaximumArrowTargetHalfWidth = 14; | 57 const int InfoBarContainerDelegate::kMaximumArrowTargetHalfWidth = 14; |
| 32 | 58 |
| 33 InfoBarContainerDelegate::InfoBarContainerDelegate() | 59 InfoBarContainerDelegate::InfoBarContainerDelegate() |
| 34 : top_arrow_target_height_(kDefaultArrowTargetHeight) { | 60 : top_arrow_target_height_(kDefaultArrowTargetHeight) { |
| 35 } | 61 } |
| 36 | 62 |
| 37 InfoBarContainerDelegate::~InfoBarContainerDelegate() { | 63 InfoBarContainerDelegate::~InfoBarContainerDelegate() { |
| 38 } | 64 } |
| 39 | 65 |
| 40 void InfoBarContainerDelegate::SetMaxTopArrowHeight( | 66 void InfoBarContainerDelegate::SetMaxTopArrowHeight( |
| 41 int height, | 67 int height, |
| 42 infobars::InfoBarContainer* container) { | 68 infobars::InfoBarContainer* container) { |
| 43 // Decrease the height by the arrow stroke thickness, which is the separator | 69 top_arrow_target_height_ = std::min(height, kMaximumArrowTargetHeight); |
|
Evan Stade
2016/04/02 02:21:42
I found a pre-existing bug where the arrow is unsh
Peter Kasting
2016/04/02 02:42:11
Make sure that the arrow tip gets drawn at the exa
Evan Stade
2016/04/04 17:24:29
yea, in the single infobar case, it copes up one p
| |
| 44 // line height, because the infobar arrow target heights are without-stroke. | |
| 45 top_arrow_target_height_ = std::min( | |
| 46 std::max(height - kSeparatorLineHeight, 0), kMaximumArrowTargetHeight); | |
| 47 container->UpdateInfoBarArrowTargetHeights(); | 70 container->UpdateInfoBarArrowTargetHeights(); |
| 48 } | 71 } |
| 49 | 72 |
| 50 int InfoBarContainerDelegate::ArrowTargetHeightForInfoBar( | 73 int InfoBarContainerDelegate::ArrowTargetHeightForInfoBar( |
| 51 size_t index, | 74 size_t index, |
| 52 const gfx::SlideAnimation& animation) const { | 75 const gfx::SlideAnimation& animation) const { |
| 53 if (!DrawInfoBarArrows(nullptr)) | 76 if (!DrawInfoBarArrows(nullptr)) |
| 54 return 0; | 77 return 0; |
| 55 if (index == 0) | 78 if (index == 0) |
| 56 return top_arrow_target_height_; | 79 return top_arrow_target_height_; |
| 57 if ((index > 1) || animation.IsShowing()) | 80 if ((index > 1) || animation.IsShowing()) |
| 58 return kDefaultArrowTargetHeight; | 81 return GetDefaultArrowTargetHeight(); |
| 59 // When the first infobar is animating closed, we animate the second infobar's | 82 // When the first infobar is animating closed, we animate the second infobar's |
| 60 // arrow target height from the default to the top target height. Note that | 83 // arrow target height from the default to the top target height. Note that |
| 61 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. | 84 // the animation values here are going from 1.0 -> 0.0 as the top bar closes. |
| 62 return top_arrow_target_height_ + static_cast<int>( | 85 return top_arrow_target_height_ + |
| 63 (kDefaultArrowTargetHeight - top_arrow_target_height_) * | 86 static_cast<int>( |
| 64 animation.GetCurrentValue()); | 87 (GetDefaultArrowTargetHeight() - top_arrow_target_height_) * |
| 88 animation.GetCurrentValue()); | |
| 65 } | 89 } |
| 66 | 90 |
| 67 void InfoBarContainerDelegate::ComputeInfoBarElementSizes( | 91 void InfoBarContainerDelegate::ComputeInfoBarElementSizes( |
| 68 const gfx::SlideAnimation& animation, | 92 const gfx::SlideAnimation& animation, |
| 69 int arrow_target_height, | 93 int arrow_target_height, |
| 70 int bar_target_height, | 94 int bar_target_height, |
| 71 int* arrow_height, | 95 int* arrow_height, |
| 72 int* arrow_half_width, | 96 int* arrow_half_width, |
| 73 int* bar_height) const { | 97 int* bar_height) const { |
| 74 // Find the desired arrow height/half-width. The arrow area is | 98 // Find the desired arrow height/half-width. The arrow area is |
| 75 // *arrow_height * *arrow_half_width. When the bar is opening or closing, | 99 // *arrow_height * *arrow_half_width. When the bar is opening or closing, |
| 76 // scaling each of these with the square root of the animation value causes a | 100 // scaling each of these with the square root of the animation value causes a |
| 77 // linear animation of the area, which matches the perception of the animation | 101 // linear animation of the area, which matches the perception of the animation |
| 78 // of the bar portion. | 102 // of the bar portion. |
| 79 double scale_factor = sqrt(animation.GetCurrentValue()); | 103 double scale_factor = sqrt(animation.GetCurrentValue()); |
| 80 *arrow_height = static_cast<int>(arrow_target_height * scale_factor); | 104 *arrow_height = static_cast<int>(arrow_target_height * scale_factor); |
| 81 if (animation.is_animating()) { | 105 if (animation.is_animating()) { |
| 82 *arrow_half_width = static_cast<int>( | 106 *arrow_half_width = static_cast<int>( |
| 83 std::min(arrow_target_height, kMaximumArrowTargetHalfWidth) * | 107 std::min(arrow_target_height, kMaximumArrowTargetHalfWidth) * |
| 84 scale_factor); | 108 scale_factor); |
| 85 } else { | 109 } else { |
| 86 // When the infobar is not animating (i.e. fully open), we set the | 110 // When the infobar is not animating (i.e. fully open), we set the |
| 87 // half-width to be proportionally the same distance between its default and | 111 // half-width to be proportionally the same distance between its default and |
| 88 // maximum values as the height is between its. | 112 // maximum values as the height is between its. |
| 89 *arrow_half_width = kDefaultArrowTargetHalfWidth + | 113 *arrow_half_width = |
| 90 ((kMaximumArrowTargetHalfWidth - kDefaultArrowTargetHalfWidth) * | 114 GetDefaultArrowTargetHalfWidth() + |
| 115 ((kMaximumArrowTargetHalfWidth - GetDefaultArrowTargetHalfWidth()) * | |
| 91 ((*arrow_height - kDefaultArrowTargetHeight) / | 116 ((*arrow_height - kDefaultArrowTargetHeight) / |
| 92 (kMaximumArrowTargetHeight - kDefaultArrowTargetHeight))); | 117 (kMaximumArrowTargetHeight - kDefaultArrowTargetHeight))); |
| 93 } | 118 } |
| 94 // Add pixels for the stroke, if the arrow is to be visible at all. Without | 119 // Add pixels for the stroke, if the arrow is to be visible at all. Without |
| 95 // this, changing the arrow height from 0 to kSeparatorLineHeight would | 120 // this, changing the arrow height from 0 to kSeparatorLineHeight would |
| 96 // produce no visible effect, because the stroke would paint atop the divider | 121 // produce no visible effect, because the stroke would paint atop the divider |
| 97 // line above the infobar. | 122 // line above the infobar. |
| 98 if (*arrow_height) | 123 if (*arrow_height && ui::MaterialDesignController::IsModeMaterial()) |
| 99 *arrow_height += kSeparatorLineHeight; | 124 *arrow_height += GetSeparatorLineHeightForLayout(); |
| 100 | 125 |
| 101 int target_height = bar_target_height != -1 | 126 int target_height = bar_target_height != -1 |
| 102 ? bar_target_height | 127 ? bar_target_height |
| 103 : ui::MaterialDesignController::IsModeMaterial() | 128 : ui::MaterialDesignController::IsModeMaterial() |
| 104 ? kDefaultBarTargetHeightMd | 129 ? kDefaultBarTargetHeightMd |
| 105 : kDefaultBarTargetHeight; | 130 : kDefaultBarTargetHeight; |
| 106 *bar_height = animation.CurrentValueBetween(0, target_height); | 131 *bar_height = animation.CurrentValueBetween(0, target_height); |
| 107 } | 132 } |
| OLD | NEW |