File: infobar_container_delegate.cc

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (92 lines) | stat: -rw-r--r-- 3,656 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// 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 "build/build_config.h"
#include "ui/gfx/animation/slide_animation.h"

#if defined(TOOLKIT_VIEWS)
#include "ui/views/window/non_client_view.h"
#endif

// static
#if defined(OS_MACOSX)
const int InfoBarContainerDelegate::kSeparatorLineHeight = 1;
#else
const int InfoBarContainerDelegate::kSeparatorLineHeight =
    views::NonClientFrameView::kClientEdgeThickness;
#endif
const int InfoBarContainerDelegate::kDefaultArrowTargetHeight = 11;

const int InfoBarContainerDelegate::kDefaultBarTargetHeight = 40;
const int InfoBarContainerDelegate::kMaximumArrowTargetHeight = 24;
const int InfoBarContainerDelegate::kDefaultArrowTargetHalfWidth =
    kDefaultArrowTargetHeight;
const int InfoBarContainerDelegate::kMaximumArrowTargetHalfWidth = 14;

InfoBarContainerDelegate::InfoBarContainerDelegate()
    : top_arrow_target_height_(kDefaultArrowTargetHeight) {}

InfoBarContainerDelegate::~InfoBarContainerDelegate() {
}

void InfoBarContainerDelegate::SetMaxTopArrowHeight(
    int height,
    infobars::InfoBarContainer* container) {
  top_arrow_target_height_ =
      std::min(std::max(height, 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)));
  }
  int target_height =
      bar_target_height == -1 ? kDefaultBarTargetHeight : bar_target_height;
  *bar_height = animation.CurrentValueBetween(0, target_height);
}