| 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/gfx/animation/slide_animation.h" | 9 #include "ui/gfx/animation/slide_animation.h" |
| 9 | 10 |
| 10 #if defined(TOOLKIT_VIEWS) | 11 #if defined(TOOLKIT_VIEWS) |
| 11 #include "ui/views/window/non_client_view.h" | 12 #include "ui/views/window/non_client_view.h" |
| 12 #endif | 13 #endif |
| 13 | 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 |
| 14 // static | 37 // static |
| 15 #if defined(OS_MACOSX) | 38 #if defined(OS_MACOSX) |
| 16 const int InfoBarContainerDelegate::kSeparatorLineHeight = 1; | 39 const int InfoBarContainerDelegate::kSeparatorLineHeight = 1; |
| 17 #else | 40 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 11; |
| 41 #elif defined(TOOLKIT_VIEWS) |
| 42 // Views comes second until the Mac browser is Views-based. |
| 18 const int InfoBarContainerDelegate::kSeparatorLineHeight = | 43 const int InfoBarContainerDelegate::kSeparatorLineHeight = |
| 19 views::NonClientFrameView::kClientEdgeThickness; | 44 views::NonClientFrameView::kClientEdgeThickness; |
| 45 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 9; |
| 20 #endif | 46 #endif |
| 21 const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 11; | 47 const int InfoBarContainerDelegate::kDefaultArrowTargetHeightMd = 11; |
| 22 | 48 |
| 23 const int InfoBarContainerDelegate::kDefaultBarTargetHeight = 40; | 49 const int InfoBarContainerDelegate::kDefaultBarTargetHeight = 36; |
| 50 const int InfoBarContainerDelegate::kDefaultBarTargetHeightMd = 40; |
| 24 const int InfoBarContainerDelegate::kMaximumArrowTargetHeight = 24; | 51 const int InfoBarContainerDelegate::kMaximumArrowTargetHeight = 24; |
| 25 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth = | 52 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth = |
| 26 kDefaultArrowTargetHeight; | 53 kDefaultArrowTargetHeight; |
| 54 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidthMd = |
| 55 kDefaultArrowTargetHeightMd; |
| 27 const int InfoBarContainerDelegate::kMaximumArrowTargetHalfWidth = 14; | 56 const int InfoBarContainerDelegate::kMaximumArrowTargetHalfWidth = 14; |
| 28 | 57 |
| 29 InfoBarContainerDelegate::InfoBarContainerDelegate() | 58 InfoBarContainerDelegate::InfoBarContainerDelegate() |
| 30 : top_arrow_target_height_(kDefaultArrowTargetHeight) {} | 59 : top_arrow_target_height_(GetDefaultArrowTargetHeight()) {} |
| 31 | 60 |
| 32 InfoBarContainerDelegate::~InfoBarContainerDelegate() { | 61 InfoBarContainerDelegate::~InfoBarContainerDelegate() { |
| 33 } | 62 } |
| 34 | 63 |
| 35 void InfoBarContainerDelegate::SetMaxTopArrowHeight( | 64 void InfoBarContainerDelegate::SetMaxTopArrowHeight( |
| 36 int height, | 65 int height, |
| 37 infobars::InfoBarContainer* container) { | 66 infobars::InfoBarContainer* container) { |
| 38 top_arrow_target_height_ = | 67 top_arrow_target_height_ = |
| 39 std::min(std::max(height, 0), kMaximumArrowTargetHeight); | 68 std::min(std::max(height - GetSeparatorLineHeightForLayout(), 0), |
| 69 kMaximumArrowTargetHeight); |
| 40 container->UpdateInfoBarArrowTargetHeights(); | 70 container->UpdateInfoBarArrowTargetHeights(); |
| 41 } | 71 } |
| 42 | 72 |
| 43 int InfoBarContainerDelegate::ArrowTargetHeightForInfoBar( | 73 int InfoBarContainerDelegate::ArrowTargetHeightForInfoBar( |
| 44 size_t index, | 74 size_t index, |
| 45 const gfx::SlideAnimation& animation) const { | 75 const gfx::SlideAnimation& animation) const { |
| 46 if (!DrawInfoBarArrows(nullptr)) | 76 if (!DrawInfoBarArrows(nullptr)) |
| 47 return 0; | 77 return 0; |
| 48 if (index == 0) | 78 if (index == 0) |
| 49 return top_arrow_target_height_; | 79 return top_arrow_target_height_; |
| 50 if ((index > 1) || animation.IsShowing()) | 80 if ((index > 1) || animation.IsShowing()) |
| 51 return kDefaultArrowTargetHeight; | 81 return GetDefaultArrowTargetHeight(); |
| 52 // 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 |
| 53 // 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 |
| 54 // 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. |
| 55 return top_arrow_target_height_ + | 85 return top_arrow_target_height_ + |
| 56 static_cast<int>( | 86 static_cast<int>( |
| 57 (kDefaultArrowTargetHeight - top_arrow_target_height_) * | 87 (GetDefaultArrowTargetHeight() - top_arrow_target_height_) * |
| 58 animation.GetCurrentValue()); | 88 animation.GetCurrentValue()); |
| 59 } | 89 } |
| 60 | 90 |
| 61 void InfoBarContainerDelegate::ComputeInfoBarElementSizes( | 91 void InfoBarContainerDelegate::ComputeInfoBarElementSizes( |
| 62 const gfx::SlideAnimation& animation, | 92 const gfx::SlideAnimation& animation, |
| 63 int arrow_target_height, | 93 int arrow_target_height, |
| 64 int bar_target_height, | 94 int bar_target_height, |
| 65 int* arrow_height, | 95 int* arrow_height, |
| 66 int* arrow_half_width, | 96 int* arrow_half_width, |
| 67 int* bar_height) const { | 97 int* bar_height) const { |
| 68 // Find the desired arrow height/half-width. The arrow area is | 98 // Find the desired arrow height/half-width. The arrow area is |
| 69 // *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, |
| 70 // 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 |
| 71 // 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 |
| 72 // of the bar portion. | 102 // of the bar portion. |
| 73 double scale_factor = sqrt(animation.GetCurrentValue()); | 103 double scale_factor = sqrt(animation.GetCurrentValue()); |
| 74 *arrow_height = static_cast<int>(arrow_target_height * scale_factor); | 104 *arrow_height = static_cast<int>(arrow_target_height * scale_factor); |
| 75 if (animation.is_animating()) { | 105 if (animation.is_animating()) { |
| 76 *arrow_half_width = static_cast<int>( | 106 *arrow_half_width = static_cast<int>( |
| 77 std::min(arrow_target_height, kMaximumArrowTargetHalfWidth) * | 107 std::min(arrow_target_height, kMaximumArrowTargetHalfWidth) * |
| 78 scale_factor); | 108 scale_factor); |
| 79 } else { | 109 } else { |
| 80 // 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 |
| 81 // 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 |
| 82 // maximum values as the height is between its. | 112 // maximum values as the height is between its. |
| 83 *arrow_half_width = | 113 *arrow_half_width = |
| 84 kDefaultArrowTargetHalfWidth + | 114 GetDefaultArrowTargetHalfWidth() + |
| 85 ((kMaximumArrowTargetHalfWidth - kDefaultArrowTargetHalfWidth) * | 115 ((kMaximumArrowTargetHalfWidth - GetDefaultArrowTargetHalfWidth()) * |
| 86 ((*arrow_height - kDefaultArrowTargetHeight) / | 116 ((*arrow_height - kDefaultArrowTargetHeight) / |
| 87 (kMaximumArrowTargetHeight - kDefaultArrowTargetHeight))); | 117 (kMaximumArrowTargetHeight - kDefaultArrowTargetHeight))); |
| 88 } | 118 } |
| 89 int target_height = | 119 // Add pixels for the stroke, if the arrow is to be visible at all. Without |
| 90 bar_target_height == -1 ? kDefaultBarTargetHeight : bar_target_height; | 120 // this, changing the arrow height from 0 to kSeparatorLineHeight would |
| 121 // produce no visible effect, because the stroke would paint atop the divider |
| 122 // line above the infobar. |
| 123 if (*arrow_height && !ui::MaterialDesignController::IsModeMaterial()) |
| 124 *arrow_height += GetSeparatorLineHeightForLayout(); |
| 125 |
| 126 int target_height = bar_target_height != -1 |
| 127 ? bar_target_height |
| 128 : ui::MaterialDesignController::IsModeMaterial() |
| 129 ? kDefaultBarTargetHeightMd |
| 130 : kDefaultBarTargetHeight; |
| 91 *bar_height = animation.CurrentValueBetween(0, target_height); | 131 *bar_height = animation.CurrentValueBetween(0, target_height); |
| 92 } | 132 } |
| OLD | NEW |