Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(124)

Unified Diff: chrome/browser/ui/infobar_container_delegate.cc

Issue 793783003: Move infobar constants and the code that uses them from components/ to chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NULL -> nullptr Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/infobar_container_delegate.h ('k') | chrome/browser/ui/views/frame/browser_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/infobar_container_delegate.cc
diff --git a/chrome/browser/ui/infobar_container_delegate.cc b/chrome/browser/ui/infobar_container_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..129cf43262ee2fc559b0b7a8a0cb3f610b4b4068
--- /dev/null
+++ b/chrome/browser/ui/infobar_container_delegate.cc
@@ -0,0 +1,85 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/infobar_container_delegate.h"
+#include "ui/gfx/animation/slide_animation.h"
+
+const int InfoBarContainerDelegate::kDefaultBarTargetHeight = 36;
+const int InfoBarContainerDelegate::kMaximumArrowTargetHeight = 24;
+const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth =
+ kDefaultArrowTargetHeight;
Lei Zhang 2014/12/12 10:11:33 This creates a static initializer and the sizes st
+const int InfoBarContainerDelegate::kMaximumArrowTargetHalfWidth = 14;
+
+InfoBarContainerDelegate::InfoBarContainerDelegate()
+ : top_arrow_target_height_(kDefaultArrowTargetHeight) {
+}
+
+InfoBarContainerDelegate::~InfoBarContainerDelegate() {
+}
+
+void InfoBarContainerDelegate::SetMaxTopArrowHeight(
+ int height,
+ infobars::InfoBarContainer* container) {
+ // Decrease the height by the arrow stroke thickness, which is the separator
+ // line height, because the infobar arrow target heights are without-stroke.
+ top_arrow_target_height_ = std::min(
+ std::max(height - kSeparatorLineHeight, 0), kMaximumArrowTargetHeight);
+ container->UpdateInfoBarArrowTargetHeights();
+}
+
+int InfoBarContainerDelegate::ArrowTargetHeightForInfoBar(
+ size_t index,
+ const gfx::SlideAnimation& animation) const {
+ if (!DrawInfoBarArrows(nullptr))
+ return 0;
+ if (index == 0)
+ return top_arrow_target_height_;
+ if ((index > 1) || animation.IsShowing())
+ return kDefaultArrowTargetHeight;
+ // When the first infobar is animating closed, we animate the second infobar's
+ // arrow target height from the default to the top target height. Note that
+ // the animation values here are going from 1.0 -> 0.0 as the top bar closes.
+ return top_arrow_target_height_ + static_cast<int>(
+ (kDefaultArrowTargetHeight - top_arrow_target_height_) *
+ animation.GetCurrentValue());
+}
+
+void InfoBarContainerDelegate::ComputeInfoBarElementSizes(
+ const gfx::SlideAnimation& animation,
+ int arrow_target_height,
+ int bar_target_height,
+ int* arrow_height,
+ int* arrow_half_width,
+ int* bar_height) const {
+ // Find the desired arrow height/half-width. The arrow area is
+ // *arrow_height * *arrow_half_width. When the bar is opening or closing,
+ // scaling each of these with the square root of the animation value causes a
+ // linear animation of the area, which matches the perception of the animation
+ // of the bar portion.
+ double scale_factor = sqrt(animation.GetCurrentValue());
+ *arrow_height = static_cast<int>(arrow_target_height * scale_factor);
+ if (animation.is_animating()) {
+ *arrow_half_width = static_cast<int>(
+ std::min(arrow_target_height, kMaximumArrowTargetHalfWidth) *
+ scale_factor);
+ } else {
+ // When the infobar is not animating (i.e. fully open), we set the
+ // half-width to be proportionally the same distance between its default and
+ // maximum values as the height is between its.
+ *arrow_half_width = kDefaultArrowTargetHalfWidth +
+ ((kMaximumArrowTargetHalfWidth - kDefaultArrowTargetHalfWidth) *
+ ((*arrow_height - kDefaultArrowTargetHeight) /
+ (kMaximumArrowTargetHeight - kDefaultArrowTargetHeight)));
+ }
+ // Add pixels for the stroke, if the arrow is to be visible at all. Without
+ // this, changing the arrow height from 0 to kSeparatorLineHeight would
+ // produce no visible effect, because the stroke would paint atop the divider
+ // line above the infobar.
+ if (*arrow_height)
+ *arrow_height += kSeparatorLineHeight;
+
+ *bar_height = animation.CurrentValueBetween(
+ 0,
+ (bar_target_height == -1) ? kDefaultBarTargetHeight : bar_target_height);
+}
« no previous file with comments | « chrome/browser/ui/infobar_container_delegate.h ('k') | chrome/browser/ui/views/frame/browser_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698