blob: 6f1769a1cd2f997c7fad429174b86e735cc2bd30 (
plain)
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
93
94
95
96
97
98
99
100
101
102
103
|
// Copyright (c) 2011 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.
#ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_H_
#define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_H_
#pragma once
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "ui/base/animation/animation_delegate.h"
#include "ui/gfx/size.h"
class InfoBarContainer;
class InfoBarDelegate;
namespace ui {
class SlideAnimation;
}
class InfoBar : public ui::AnimationDelegate {
public:
explicit InfoBar(InfoBarDelegate* delegate);
virtual ~InfoBar();
InfoBarDelegate* delegate() { return delegate_; }
void set_container(InfoBarContainer* container) { container_ = container; }
// Makes the infobar visible. If |animate| is true, the infobar is then
// animated to full size.
void Show(bool animate);
// Makes the infobar hidden. If |animate| is true, the infobar is first
// animated to zero size. Once the infobar is hidden, it is removed from its
// container (triggering its deletion), and its delegate is closed.
void Hide(bool animate);
int arrow_height() const { return arrow_height_; }
int total_height() const { return arrow_height_ + bar_height_; }
protected:
// The target heights of the InfoBar arrow and bar portions, regardless of
// what their current heights are (due to animation). Platforms must define
// these!
static const int kArrowTargetHeight;
static const int kDefaultBarTargetHeight;
// ui::AnimationDelegate:
virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
// Called when the user closes the infobar, notifies the delegate we've been
// dismissed and forwards a removal request to our owner.
void RemoveInfoBar();
// Changes the target height of the main ("bar") portion of the infobar.
void SetBarTargetHeight(int height);
// Given a control with size |prefsize|, returns the centered y position
// within us, taking into account animation so the control "slides in" (or
// out) as we animate open and closed.
int OffsetY(const gfx::Size& prefsize) const;
// Passthrough to the container function of the same name.
bool DrawInfoBarArrows(int* x) const;
ui::SlideAnimation* animation() { return animation_.get(); }
const ui::SlideAnimation* animation() const { return animation_.get(); }
int bar_height() const { return bar_height_; }
// Platforms may optionally override these if they need to do work during
// processing of the given calls.
virtual void PlatformSpecificHide(bool animate) {}
virtual void PlatformSpecificOnHeightRecalculated() {}
private:
// ui::AnimationDelegate:
virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
// Finds the new desired arrow and bar heights, and if they differ from the
// current ones, calls PlatformSpecificOnHeightRecalculated() and informs our
// container our height has changed.
void RecalculateHeight();
// Checks whether we're closed. If so, notifies the container that it should
// remove us (which will cause the platform-specific code to asynchronously
// delete us) and closes the delegate.
void MaybeDelete();
InfoBarDelegate* delegate_;
InfoBarContainer* container_;
scoped_ptr<ui::SlideAnimation> animation_;
// The target height for the bar portion of the InfoBarView.
int bar_target_height_;
// The current heights of the arrow and bar portions.
int arrow_height_;
int bar_height_;
DISALLOW_COPY_AND_ASSIGN(InfoBar);
};
#endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_H_
|