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

Side by Side Diff: chrome/browser/ui/views/infobars/infobar.h

Issue 6989001: Misc. infobar stuff: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_H_
6 #define CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "base/scoped_ptr.h"
11 #include "ui/base/animation/animation_delegate.h"
12 #include "ui/gfx/size.h"
13
14 class InfoBarContainer;
15 class InfoBarDelegate;
16
17 namespace ui {
18 class SlideAnimation;
19 }
20
21 class InfoBar : public ui::AnimationDelegate {
22 public:
23 explicit InfoBar(InfoBarDelegate* delegate);
24 virtual ~InfoBar();
25
26 // Platforms must define these.
27 static const int kSeparatorLineHeight;
28 static const int kDefaultArrowTargetHeight;
29 static const int kMaximumArrowTargetHeight;
30 // The half-width (see comments on |arrow_half_width_| below) scales to its
31 // default and maximum values proportionally to how the height scales to its.
32 static const int kDefaultArrowTargetHalfWidth;
33 static const int kMaximumArrowTargetHalfWidth;
34
35 InfoBarDelegate* delegate() { return delegate_; }
36 void set_container(InfoBarContainer* container) { container_ = container; }
37
38 // Makes the infobar visible. If |animate| is true, the infobar is then
39 // animated to full size.
40 void Show(bool animate);
41
42 // Makes the infobar hidden. If |animate| is true, the infobar is first
43 // animated to zero size. Once the infobar is hidden, it is removed from its
44 // container (triggering its deletion), and its delegate is closed.
45 void Hide(bool animate);
46
47 // Changes the target height of the arrow portion of the infobar. This has no
48 // effect once the infobar is animating closed.
49 void SetArrowTargetHeight(int height);
50
51 const ui::SlideAnimation* animation() const { return animation_.get(); }
52 int arrow_height() const { return arrow_height_; }
53 int total_height() const { return arrow_height_ + bar_height_; }
54
55 protected:
56 // Platforms must define this.
57 static const int kDefaultBarTargetHeight;
58
59 // ui::AnimationDelegate:
60 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
61
62 // Called when the user closes the infobar, notifies the delegate we've been
63 // dismissed and forwards a removal request to our owner.
64 void RemoveInfoBar();
65
66 // Changes the target height of the main ("bar") portion of the infobar.
67 void SetBarTargetHeight(int height);
68
69 // Given a control with size |prefsize|, returns the centered y position
70 // within us, taking into account animation so the control "slides in" (or
71 // out) as we animate open and closed.
72 int OffsetY(const gfx::Size& prefsize) const;
73
74 const InfoBarContainer* container() const { return container_; }
75 ui::SlideAnimation* animation() { return animation_.get(); }
76 int arrow_half_width() const { return arrow_half_width_; }
77 int bar_height() const { return bar_height_; }
78
79 // Platforms may optionally override these if they need to do work during
80 // processing of the given calls.
81 virtual void PlatformSpecificHide(bool animate) {}
82 virtual void PlatformSpecificOnHeightsRecalculated() {}
83
84 private:
85 // ui::AnimationDelegate:
86 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
87
88 // Finds the new desired arrow and bar heights, and if they differ from the
89 // current ones, calls PlatformSpecificOnHeightRecalculated(). Informs our
90 // container our state has changed if either the heights have changed or
91 // |force_notify| is set.
92 void RecalculateHeights(bool force_notify);
93
94 // Checks whether we're closed. If so, notifies the container that it should
95 // remove us (which will cause the platform-specific code to asynchronously
96 // delete us) and closes the delegate.
97 void MaybeDelete();
98
99 InfoBarDelegate* delegate_;
100 InfoBarContainer* container_;
101 scoped_ptr<ui::SlideAnimation> animation_;
102
103 // The current and target heights of the arrow and bar portions, and half the
104 // current arrow width. (It's easier to work in half-widths as we draw the
105 // arrow as two halves on either side of a center point.)
106 int arrow_height_; // Includes both fill and top stroke.
107 int arrow_target_height_;
108 int arrow_half_width_; // Includes only fill.
109 int bar_height_; // Includes both fill and bottom separator.
110 int bar_target_height_;
111
112 DISALLOW_COPY_AND_ASSIGN(InfoBar);
113 };
114
115 #endif // CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/extension_infobar.cc ('k') | chrome/browser/ui/views/infobars/infobar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698