blob: 7b94735707cbf190ed4e47bfa6afbfca25faa75f (
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
// Copyright (c) 2006-2008 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_VIEWS_INFOBARS_INFOBARS_H_
#define CHROME_BROWSER_VIEWS_INFOBARS_INFOBARS_H_
#include "chrome/browser/infobar_delegate.h"
#include "chrome/views/base_button.h"
#include "chrome/views/native_button.h"
class InfoBarContainer;
class SlideAnimation;
namespace views {
class Button;
class ExternalFocusTracker;
class ImageView;
class Label;
}
// This file contains implementations for some general purpose InfoBars. See
// chrome/browser/infobar_delegate.h for the delegate interface(s) that you must
// implement to use these.
class InfoBar : public views::View,
public views::BaseButton::ButtonListener,
public AnimationDelegate {
public:
explicit InfoBar(InfoBarDelegate* delegate);
virtual ~InfoBar();
InfoBarDelegate* delegate() const { return delegate_; }
void set_container(InfoBarContainer* container) { container_ = container; }
// Starts animating the InfoBar open.
void AnimateOpen();
// Opens the InfoBar immediately.
void Open();
// Starts animating the InfoBar closed. It will not be closed until the
// animation has completed, when |Close| will be called.
void AnimateClose();
// Closes the InfoBar immediately and removes it from its container. Notifies
// the delegate that it has closed. The InfoBar is deleted after this function
// is called.
void Close();
// Overridden from views::View:
virtual gfx::Size GetPreferredSize();
virtual void Layout();
protected:
// Overridden from views::View:
virtual void ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child);
// Returns the available width of the View for use by child view layout,
// excluding the close button.
virtual int GetAvailableWidth() const;
private:
// Overridden from views::Button::ButtonListener:
virtual void ButtonPressed(views::BaseButton* sender);
// Overridden from AnimationDelegate:
virtual void AnimationProgressed(const Animation* animation);
virtual void AnimationEnded(const Animation* animation);
// The InfoBar's container
InfoBarContainer* container_;
// The InfoBar's delegate.
InfoBarDelegate* delegate_;
// The Close Button at the right edge of the InfoBar.
views::Button* close_button_;
// The animation that runs when the InfoBar is opened or closed.
scoped_ptr<SlideAnimation> animation_;
// Tracks and stores the last focused view which is not the InfoBar or any of
// its children. Used to restore focus once the InfoBar is closed.
scoped_ptr<views::ExternalFocusTracker> focus_tracker_;
DISALLOW_COPY_AND_ASSIGN(InfoBar);
};
class AlertInfoBar : public InfoBar {
public:
explicit AlertInfoBar(AlertInfoBarDelegate* delegate);
virtual ~AlertInfoBar();
// Overridden from views::View:
virtual void Layout();
protected:
views::Label* label() const { return label_; }
views::ImageView* icon() const { return icon_; }
private:
AlertInfoBarDelegate* GetDelegate();
views::Label* label_;
views::ImageView* icon_;
DISALLOW_COPY_AND_ASSIGN(AlertInfoBar);
};
class ConfirmInfoBar : public AlertInfoBar,
public views::NativeButton::Listener {
public:
explicit ConfirmInfoBar(ConfirmInfoBarDelegate* delegate);
virtual ~ConfirmInfoBar();
// Overridden from views::View:
virtual void Layout();
protected:
// Overridden from views::View:
virtual void ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child);
// Overridden from views::NativeButton::Listener:
virtual void ButtonPressed(views::NativeButton* sender);
// Overridden from InfoBar:
virtual int GetAvailableWidth() const;
private:
void Init();
ConfirmInfoBarDelegate* GetDelegate();
views::NativeButton* ok_button_;
views::NativeButton* cancel_button_;
bool initialized_;
DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBar);
};
#endif // #ifndef CHROME_BROWSER_VIEWS_INFOBARS_INFOBARS_H_
|