OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_INFOBARS_CORE_INFOBAR_H_ | 5 #ifndef COMPONENTS_INFOBARS_CORE_INFOBAR_H_ |
6 #define COMPONENTS_INFOBARS_CORE_INFOBAR_H_ | 6 #define COMPONENTS_INFOBARS_CORE_INFOBAR_H_ |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "components/infobars/core/infobar_delegate.h" | 11 #include "components/infobars/core/infobar_delegate.h" |
12 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
13 #include "ui/gfx/animation/animation_delegate.h" | 13 #include "ui/gfx/animation/animation_delegate.h" |
14 #include "ui/gfx/animation/slide_animation.h" | 14 #include "ui/gfx/animation/slide_animation.h" |
15 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
16 | 16 |
17 namespace infobars { | 17 namespace infobars { |
18 | 18 |
19 class InfoBarContainer; | 19 class InfoBarContainer; |
20 class InfoBarManager; | 20 class InfoBarManager; |
21 | 21 |
| 22 // InfoBarConstants holds embedder specific constants used by InfoBar |
| 23 // animation implementation. |
| 24 struct InfoBarConstants { |
| 25 int separator_line_height; |
| 26 int default_bar_target_height; |
| 27 int default_arrow_target_height; |
| 28 int maximum_arrow_target_height; |
| 29 // The half-width (see comments on |arrow_half_width_| below) scales to its |
| 30 // default and maximum values proportionally to how the height scales to its. |
| 31 int default_arrow_target_half_width; |
| 32 int maximum_arrow_target_half_width; |
| 33 }; |
| 34 |
22 // InfoBar is a cross-platform base class for an infobar "view" (in the MVC | 35 // InfoBar is a cross-platform base class for an infobar "view" (in the MVC |
23 // sense), which owns a corresponding InfoBarDelegate "model". Typically, | 36 // sense), which owns a corresponding InfoBarDelegate "model". Typically, |
24 // a caller will call XYZInfoBarDelegate::Create() and pass in the | 37 // a caller will call XYZInfoBarDelegate::Create() and pass in the |
25 // InfoBarManager for the relevant tab. This will create an XYZInfoBarDelegate, | 38 // InfoBarManager for the relevant tab. This will create an XYZInfoBarDelegate, |
26 // create a platform-specific subclass of InfoBar to own it, and then call | 39 // create a platform-specific subclass of InfoBar to own it, and then call |
27 // InfoBarManager::AddInfoBar() to give it ownership of the infobar. | 40 // InfoBarManager::AddInfoBar() to give it ownership of the infobar. |
28 // During its life, the InfoBar may be shown and hidden as the owning tab is | 41 // During its life, the InfoBar may be shown and hidden as the owning tab is |
29 // switched between the foreground and background. Eventually, InfoBarManager | 42 // switched between the foreground and background. Eventually, InfoBarManager |
30 // will instruct the InfoBar to close itself. At this point, the InfoBar will | 43 // will instruct the InfoBar to close itself. At this point, the InfoBar will |
31 // optionally animate closed; once it's no longer visible, it deletes itself, | 44 // optionally animate closed; once it's no longer visible, it deletes itself, |
32 // destroying the InfoBarDelegate in the process. | 45 // destroying the InfoBarDelegate in the process. |
33 // | 46 // |
34 // Thus, InfoBarDelegate and InfoBar implementations can assume they share | 47 // Thus, InfoBarDelegate and InfoBar implementations can assume they share |
35 // lifetimes, and not NULL-check each other; but if one needs to reach back into | 48 // lifetimes, and not NULL-check each other; but if one needs to reach back into |
36 // the owning InfoBarManager, it must check whether that's still possible. | 49 // the owning InfoBarManager, it must check whether that's still possible. |
37 class InfoBar : public gfx::AnimationDelegate { | 50 class InfoBar : public gfx::AnimationDelegate { |
38 public: | 51 public: |
39 // These are the types passed as Details for infobar-related notifications. | 52 // These are the types passed as Details for infobar-related notifications. |
40 typedef InfoBar AddedDetails; | 53 typedef InfoBar AddedDetails; |
41 typedef std::pair<InfoBar*, bool> RemovedDetails; | 54 typedef std::pair<InfoBar*, bool> RemovedDetails; |
42 | 55 |
43 // Platforms must define these. | 56 InfoBar(scoped_ptr<InfoBarDelegate> delegate); |
44 static const int kDefaultBarTargetHeight; | |
45 static const int kSeparatorLineHeight; | |
46 static const int kDefaultArrowTargetHeight; | |
47 static const int kMaximumArrowTargetHeight; | |
48 // The half-width (see comments on |arrow_half_width_| below) scales to its | |
49 // default and maximum values proportionally to how the height scales to its. | |
50 static const int kDefaultArrowTargetHalfWidth; | |
51 static const int kMaximumArrowTargetHalfWidth; | |
52 | |
53 explicit InfoBar(scoped_ptr<InfoBarDelegate> delegate); | |
54 ~InfoBar() override; | 57 ~InfoBar() override; |
55 | 58 |
56 static SkColor GetTopColor(InfoBarDelegate::Type infobar_type); | 59 static SkColor GetTopColor(InfoBarDelegate::Type infobar_type); |
57 static SkColor GetBottomColor(InfoBarDelegate::Type infobar_type); | 60 static SkColor GetBottomColor(InfoBarDelegate::Type infobar_type); |
58 | 61 |
59 InfoBarManager* owner() { return owner_; } | 62 InfoBarManager* owner() { return owner_; } |
60 InfoBarDelegate* delegate() const { return delegate_.get(); } | 63 InfoBarDelegate* delegate() const { return delegate_.get(); } |
61 void set_container(InfoBarContainer* container) { container_ = container; } | 64 void set_container(InfoBarContainer* container) { container_ = container; } |
62 | 65 |
63 // Sets |owner_|. This also calls StoreActiveEntryUniqueID() on |delegate_|. | 66 // Sets |owner_|. This also calls StoreActiveEntryUniqueID() on |delegate_|. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 int arrow_half_width_; // Includes only fill. | 145 int arrow_half_width_; // Includes only fill. |
143 int bar_height_; // Includes both fill and bottom separator. | 146 int bar_height_; // Includes both fill and bottom separator. |
144 int bar_target_height_; | 147 int bar_target_height_; |
145 | 148 |
146 DISALLOW_COPY_AND_ASSIGN(InfoBar); | 149 DISALLOW_COPY_AND_ASSIGN(InfoBar); |
147 }; | 150 }; |
148 | 151 |
149 } // namespace infobars | 152 } // namespace infobars |
150 | 153 |
151 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_H_ | 154 #endif // COMPONENTS_INFOBARS_CORE_INFOBAR_H_ |
OLD | NEW |