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

Side by Side 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: Bad include path 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/infobar_container_delegate.h"
6 #include "ui/gfx/animation/slide_animation.h"
7
8 const int InfoBarContainerDelegate::kDefaultBarTargetHeight = 36;
9 const int InfoBarContainerDelegate::kMaximumArrowTargetHeight = 24;
10 const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth =
11 kDefaultArrowTargetHeight;
12 const int InfoBarContainerDelegate::kMaximumArrowTargetHalfWidth = 14;
13
14 InfoBarContainerDelegate::InfoBarContainerDelegate()
15 : top_arrow_target_height_(kDefaultArrowTargetHeight) {
16 }
17
18 InfoBarContainerDelegate::~InfoBarContainerDelegate() {
19 }
20
21 void InfoBarContainerDelegate::SetMaxTopArrowHeight(
22 int height,
23 infobars::InfoBarContainer* container) {
24 // Decrease the height by the arrow stroke thickness, which is the separator
25 // line height, because the infobar arrow target heights are without-stroke.
26 top_arrow_target_height_ = std::min(
27 std::max(height - kSeparatorLineHeight, 0), kMaximumArrowTargetHeight);
28 container->UpdateInfoBarArrowTargetHeights();
29 }
30
31 int InfoBarContainerDelegate::ArrowTargetHeightForInfoBar(
32 size_t index,
33 const gfx::SlideAnimation& animation) const {
34 if (!DrawInfoBarArrows(NULL))
sdefresne 2014/12/11 10:33:48 nit: maybe uses nullptr instead of NULL in those n
Peter Kasting 2014/12/12 01:52:24 Ah, yeah, I should have fixed that instead of copy
35 return 0;
36 if (index == 0)
37 return top_arrow_target_height_;
38 if ((index > 1) || animation.IsShowing())
39 return kDefaultArrowTargetHeight;
40 // When the first infobar is animating closed, we animate the second infobar's
41 // arrow target height from the default to the top target height. Note that
42 // the animation values here are going from 1.0 -> 0.0 as the top bar closes.
43 return top_arrow_target_height_ + static_cast<int>(
44 (kDefaultArrowTargetHeight - top_arrow_target_height_) *
45 animation.GetCurrentValue());
46 }
47
48 void InfoBarContainerDelegate::ComputeInfoBarElementSizes(
49 const gfx::SlideAnimation& animation,
50 int arrow_target_height,
51 int bar_target_height,
52 int* arrow_height,
53 int* arrow_half_width,
54 int* bar_height) const {
55 // Find the desired arrow height/half-width. The arrow area is
56 // *arrow_height * *arrow_half_width. When the bar is opening or closing,
57 // scaling each of these with the square root of the animation value causes a
58 // linear animation of the area, which matches the perception of the animation
59 // of the bar portion.
60 double scale_factor = sqrt(animation.GetCurrentValue());
61 *arrow_height = static_cast<int>(arrow_target_height * scale_factor);
62 if (animation.is_animating()) {
63 *arrow_half_width = static_cast<int>(
64 std::min(arrow_target_height, kMaximumArrowTargetHalfWidth) *
65 scale_factor);
66 } else {
67 // When the infobar is not animating (i.e. fully open), we set the
68 // half-width to be proportionally the same distance between its default and
69 // maximum values as the height is between its.
70 *arrow_half_width = kDefaultArrowTargetHalfWidth +
71 ((kMaximumArrowTargetHalfWidth - kDefaultArrowTargetHalfWidth) *
72 ((*arrow_height - kDefaultArrowTargetHeight) /
73 (kMaximumArrowTargetHeight - kDefaultArrowTargetHeight)));
74 }
75 // Add pixels for the stroke, if the arrow is to be visible at all. Without
76 // this, changing the arrow height from 0 to kSeparatorLineHeight would
77 // produce no visible effect, because the stroke would paint atop the divider
78 // line above the infobar.
79 if (*arrow_height)
80 *arrow_height += kSeparatorLineHeight;
81
82 *bar_height = animation.CurrentValueBetween(
83 0,
84 (bar_target_height == -1) ? kDefaultBarTargetHeight : bar_target_height);
85 }
OLDNEW
« 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