[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 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 | |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_INFOBARS_INFOBAR_H_ |
| 6 | #define CHROME_BROWSER_INFOBARS_INFOBAR_H_ |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 7 | #pragma once |
| 8 | |
[email protected] | 2e2f6a1e | 2011-07-01 18:03:35 | [diff] [blame] | 9 | #include <utility> |
[email protected] | ee57440 | 2011-06-21 17:49:35 | [diff] [blame] | 10 | |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | 0ef0196 | 2011-06-14 08:33:37 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | 2e2f6a1e | 2011-07-01 18:03:35 | [diff] [blame] | 13 | #include "build/build_config.h" |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 14 | #include "chrome/browser/infobars/infobar_delegate.h" |
[email protected] | c3217be5 | 2011-06-07 21:14:03 | [diff] [blame] | 15 | #include "third_party/skia/include/core/SkColor.h" |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 16 | #include "ui/base/animation/animation_delegate.h" |
[email protected] | 1a53f54 | 2011-06-22 20:02:05 | [diff] [blame] | 17 | #include "ui/base/animation/slide_animation.h" |
[email protected] | cb9cf34 | 2011-04-08 01:21:09 | [diff] [blame] | 18 | #include "ui/gfx/size.h" |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 19 | |
[email protected] | c3217be5 | 2011-06-07 21:14:03 | [diff] [blame] | 20 | // TODO(sail): These functions should be static methods in the InfoBar class |
| 21 | // below once all platforms use that class. |
| 22 | SkColor GetInfoBarTopColor(InfoBarDelegate::Type infobar_type); |
| 23 | SkColor GetInfoBarBottomColor(InfoBarDelegate::Type infobar_type); |
| 24 | |
[email protected] | 2e2f6a1e | 2011-07-01 18:03:35 | [diff] [blame] | 25 | // TODO(pkasting): Same with these notification-related typedefs. |
| 26 | typedef InfoBarDelegate InfoBarAddedDetails; |
| 27 | typedef std::pair<InfoBarDelegate*, bool> InfoBarRemovedDetails; |
| 28 | typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> InfoBarReplacedDetails; |
| 29 | |
[email protected] | ee57440 | 2011-06-21 17:49:35 | [diff] [blame] | 30 | // TODO(pkasting): Port Mac to use this. |
| 31 | #if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) |
[email protected] | c3217be5 | 2011-06-07 21:14:03 | [diff] [blame] | 32 | |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 33 | class InfoBarContainer; |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 34 | class InfoBarTabHelper; |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 35 | |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 36 | class InfoBar : public ui::AnimationDelegate { |
| 37 | public: |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 38 | InfoBar(InfoBarTabHelper* owner, InfoBarDelegate* delegate); |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 39 | virtual ~InfoBar(); |
| 40 | |
[email protected] | 2a28dc2 | 2011-04-20 06:25:10 | [diff] [blame] | 41 | // Platforms must define these. |
[email protected] | 9824015a | 2011-08-17 14:07:44 | [diff] [blame] | 42 | static const int kDefaultBarTargetHeight; |
[email protected] | 2a28dc2 | 2011-04-20 06:25:10 | [diff] [blame] | 43 | static const int kSeparatorLineHeight; |
| 44 | static const int kDefaultArrowTargetHeight; |
| 45 | static const int kMaximumArrowTargetHeight; |
| 46 | // The half-width (see comments on |arrow_half_width_| below) scales to its |
| 47 | // default and maximum values proportionally to how the height scales to its. |
| 48 | static const int kDefaultArrowTargetHalfWidth; |
| 49 | static const int kMaximumArrowTargetHalfWidth; |
| 50 | |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 51 | InfoBarDelegate* delegate() { return delegate_; } |
| 52 | void set_container(InfoBarContainer* container) { container_ = container; } |
| 53 | |
| 54 | // Makes the infobar visible. If |animate| is true, the infobar is then |
| 55 | // animated to full size. |
| 56 | void Show(bool animate); |
| 57 | |
| 58 | // Makes the infobar hidden. If |animate| is true, the infobar is first |
| 59 | // animated to zero size. Once the infobar is hidden, it is removed from its |
| 60 | // container (triggering its deletion), and its delegate is closed. |
| 61 | void Hide(bool animate); |
| 62 | |
[email protected] | 2a28dc2 | 2011-04-20 06:25:10 | [diff] [blame] | 63 | // Changes the target height of the arrow portion of the infobar. This has no |
| 64 | // effect once the infobar is animating closed. |
| 65 | void SetArrowTargetHeight(int height); |
| 66 | |
[email protected] | 661f385e | 2011-06-29 23:48:26 | [diff] [blame] | 67 | // Notifies the infobar that it is no longer owned and should close its |
| 68 | // delegate once it is invisible. |
| 69 | void CloseSoon(); |
| 70 | |
[email protected] | 1a53f54 | 2011-06-22 20:02:05 | [diff] [blame] | 71 | const ui::SlideAnimation& animation() const { return animation_; } |
[email protected] | ee12087 | 2011-04-15 01:37:06 | [diff] [blame] | 72 | int arrow_height() const { return arrow_height_; } |
[email protected] | ee57440 | 2011-06-21 17:49:35 | [diff] [blame] | 73 | int arrow_target_height() const { return arrow_target_height_; } |
| 74 | int arrow_half_width() const { return arrow_half_width_; } |
[email protected] | ee12087 | 2011-04-15 01:37:06 | [diff] [blame] | 75 | int total_height() const { return arrow_height_ + bar_height_; } |
[email protected] | cb9cf34 | 2011-04-08 01:21:09 | [diff] [blame] | 76 | |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 77 | protected: |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 78 | // ui::AnimationDelegate: |
| 79 | virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 80 | |
[email protected] | 9f507a90 | 2011-07-28 18:45:11 | [diff] [blame] | 81 | // Forwards a close request to our owner. |
[email protected] | 70d891ab | 2011-09-29 22:03:31 | [diff] [blame] | 82 | // NOTE: Subclasses should not call this if we're already unowned. |
[email protected] | 9f507a90 | 2011-07-28 18:45:11 | [diff] [blame] | 83 | void RemoveSelf(); |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 84 | |
[email protected] | cb9cf34 | 2011-04-08 01:21:09 | [diff] [blame] | 85 | // Changes the target height of the main ("bar") portion of the infobar. |
| 86 | void SetBarTargetHeight(int height); |
| 87 | |
| 88 | // Given a control with size |prefsize|, returns the centered y position |
| 89 | // within us, taking into account animation so the control "slides in" (or |
| 90 | // out) as we animate open and closed. |
| 91 | int OffsetY(const gfx::Size& prefsize) const; |
| 92 | |
[email protected] | d4e3221 | 2011-07-15 18:36:49 | [diff] [blame] | 93 | bool owned() const { return !!owner_; } |
[email protected] | 9ac174e9 | 2011-04-16 00:58:56 | [diff] [blame] | 94 | const InfoBarContainer* container() const { return container_; } |
[email protected] | ee57440 | 2011-06-21 17:49:35 | [diff] [blame] | 95 | InfoBarContainer* container() { return container_; } |
[email protected] | 1a53f54 | 2011-06-22 20:02:05 | [diff] [blame] | 96 | ui::SlideAnimation* animation() { return &animation_; } |
[email protected] | cb9cf34 | 2011-04-08 01:21:09 | [diff] [blame] | 97 | int bar_height() const { return bar_height_; } |
[email protected] | ee57440 | 2011-06-21 17:49:35 | [diff] [blame] | 98 | int bar_target_height() const { return bar_target_height_; } |
[email protected] | 1c89c290 | 2011-04-02 22:47:36 | [diff] [blame] | 99 | |
| 100 | // Platforms may optionally override these if they need to do work during |
| 101 | // processing of the given calls. |
[email protected] | ee57440 | 2011-06-21 17:49:35 | [diff] [blame] | 102 | virtual void PlatformSpecificShow(bool animate) {} |
[email protected] | 1c89c290 | 2011-04-02 22:47:36 | [diff] [blame] | 103 | virtual void PlatformSpecificHide(bool animate) {} |
[email protected] | f77c7bd6 | 2011-09-23 23:30:25 | [diff] [blame] | 104 | virtual void PlatformSpecificOnCloseSoon() {} |
[email protected] | 2a28dc2 | 2011-04-20 06:25:10 | [diff] [blame] | 105 | virtual void PlatformSpecificOnHeightsRecalculated() {} |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 106 | |
| 107 | private: |
| 108 | // ui::AnimationDelegate: |
| 109 | virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 110 | |
[email protected] | ee12087 | 2011-04-15 01:37:06 | [diff] [blame] | 111 | // Finds the new desired arrow and bar heights, and if they differ from the |
[email protected] | 4f2d40d | 2011-05-05 01:33:30 | [diff] [blame] | 112 | // current ones, calls PlatformSpecificOnHeightRecalculated(). Informs our |
| 113 | // container our state has changed if either the heights have changed or |
| 114 | // |force_notify| is set. |
| 115 | void RecalculateHeights(bool force_notify); |
[email protected] | cb9cf34 | 2011-04-08 01:21:09 | [diff] [blame] | 116 | |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 117 | // Checks whether we're closed. If so, notifies the container that it should |
| 118 | // remove us (which will cause the platform-specific code to asynchronously |
| 119 | // delete us) and closes the delegate. |
| 120 | void MaybeDelete(); |
| 121 | |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 122 | InfoBarTabHelper* owner_; |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 123 | InfoBarDelegate* delegate_; |
| 124 | InfoBarContainer* container_; |
[email protected] | 1a53f54 | 2011-06-22 20:02:05 | [diff] [blame] | 125 | ui::SlideAnimation animation_; |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 126 | |
[email protected] | 2a28dc2 | 2011-04-20 06:25:10 | [diff] [blame] | 127 | // The current and target heights of the arrow and bar portions, and half the |
| 128 | // current arrow width. (It's easier to work in half-widths as we draw the |
| 129 | // arrow as two halves on either side of a center point.) |
| 130 | int arrow_height_; // Includes both fill and top stroke. |
| 131 | int arrow_target_height_; |
| 132 | int arrow_half_width_; // Includes only fill. |
| 133 | int bar_height_; // Includes both fill and bottom separator. |
[email protected] | cb9cf34 | 2011-04-08 01:21:09 | [diff] [blame] | 134 | int bar_target_height_; |
| 135 | |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 136 | DISALLOW_COPY_AND_ASSIGN(InfoBar); |
| 137 | }; |
| 138 | |
[email protected] | c31f84b | 2011-06-02 21:41:34 | [diff] [blame] | 139 | #elif defined(OS_MACOSX) |
| 140 | #include "chrome/browser/ui/cocoa/infobars/infobar.h" |
| 141 | #endif |
[email protected] | c3217be5 | 2011-06-07 21:14:03 | [diff] [blame] | 142 | |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 143 | #endif // CHROME_BROWSER_INFOBARS_INFOBAR_H_ |