blob: 35095f4933f6733346cf9df5b5d71e5632ea89de [file] [log] [blame]
[email protected]6c6614f12011-03-31 18:51:421// 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]95a33ed62011-09-30 15:07:085#ifndef CHROME_BROWSER_INFOBARS_INFOBAR_H_
6#define CHROME_BROWSER_INFOBARS_INFOBAR_H_
[email protected]6c6614f12011-03-31 18:51:427#pragma once
8
[email protected]2e2f6a1e2011-07-01 18:03:359#include <utility>
[email protected]ee574402011-06-21 17:49:3510
[email protected]6c6614f12011-03-31 18:51:4211#include "base/basictypes.h"
[email protected]0ef01962011-06-14 08:33:3712#include "base/memory/scoped_ptr.h"
[email protected]2e2f6a1e2011-07-01 18:03:3513#include "build/build_config.h"
[email protected]95a33ed62011-09-30 15:07:0814#include "chrome/browser/infobars/infobar_delegate.h"
[email protected]c3217be52011-06-07 21:14:0315#include "third_party/skia/include/core/SkColor.h"
[email protected]6c6614f12011-03-31 18:51:4216#include "ui/base/animation/animation_delegate.h"
[email protected]1a53f542011-06-22 20:02:0517#include "ui/base/animation/slide_animation.h"
[email protected]cb9cf342011-04-08 01:21:0918#include "ui/gfx/size.h"
[email protected]6c6614f12011-03-31 18:51:4219
[email protected]c3217be52011-06-07 21:14:0320// TODO(sail): These functions should be static methods in the InfoBar class
21// below once all platforms use that class.
22SkColor GetInfoBarTopColor(InfoBarDelegate::Type infobar_type);
23SkColor GetInfoBarBottomColor(InfoBarDelegate::Type infobar_type);
24
[email protected]2e2f6a1e2011-07-01 18:03:3525// TODO(pkasting): Same with these notification-related typedefs.
26typedef InfoBarDelegate InfoBarAddedDetails;
27typedef std::pair<InfoBarDelegate*, bool> InfoBarRemovedDetails;
28typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> InfoBarReplacedDetails;
29
[email protected]ee574402011-06-21 17:49:3530// TODO(pkasting): Port Mac to use this.
31#if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK)
[email protected]c3217be52011-06-07 21:14:0332
[email protected]6c6614f12011-03-31 18:51:4233class InfoBarContainer;
[email protected]95a33ed62011-09-30 15:07:0834class InfoBarTabHelper;
[email protected]6c6614f12011-03-31 18:51:4235
[email protected]6c6614f12011-03-31 18:51:4236class InfoBar : public ui::AnimationDelegate {
37 public:
[email protected]95a33ed62011-09-30 15:07:0838 InfoBar(InfoBarTabHelper* owner, InfoBarDelegate* delegate);
[email protected]6c6614f12011-03-31 18:51:4239 virtual ~InfoBar();
40
[email protected]2a28dc22011-04-20 06:25:1041 // Platforms must define these.
[email protected]9824015a2011-08-17 14:07:4442 static const int kDefaultBarTargetHeight;
[email protected]2a28dc22011-04-20 06:25:1043 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]6c6614f12011-03-31 18:51:4251 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]2a28dc22011-04-20 06:25:1063 // 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]661f385e2011-06-29 23:48:2667 // 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]1a53f542011-06-22 20:02:0571 const ui::SlideAnimation& animation() const { return animation_; }
[email protected]ee120872011-04-15 01:37:0672 int arrow_height() const { return arrow_height_; }
[email protected]ee574402011-06-21 17:49:3573 int arrow_target_height() const { return arrow_target_height_; }
74 int arrow_half_width() const { return arrow_half_width_; }
[email protected]ee120872011-04-15 01:37:0675 int total_height() const { return arrow_height_ + bar_height_; }
[email protected]cb9cf342011-04-08 01:21:0976
[email protected]6c6614f12011-03-31 18:51:4277 protected:
[email protected]6c6614f12011-03-31 18:51:4278 // ui::AnimationDelegate:
79 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
80
[email protected]9f507a902011-07-28 18:45:1181 // Forwards a close request to our owner.
[email protected]70d891ab2011-09-29 22:03:3182 // NOTE: Subclasses should not call this if we're already unowned.
[email protected]9f507a902011-07-28 18:45:1183 void RemoveSelf();
[email protected]6c6614f12011-03-31 18:51:4284
[email protected]cb9cf342011-04-08 01:21:0985 // 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]d4e32212011-07-15 18:36:4993 bool owned() const { return !!owner_; }
[email protected]9ac174e92011-04-16 00:58:5694 const InfoBarContainer* container() const { return container_; }
[email protected]ee574402011-06-21 17:49:3595 InfoBarContainer* container() { return container_; }
[email protected]1a53f542011-06-22 20:02:0596 ui::SlideAnimation* animation() { return &animation_; }
[email protected]cb9cf342011-04-08 01:21:0997 int bar_height() const { return bar_height_; }
[email protected]ee574402011-06-21 17:49:3598 int bar_target_height() const { return bar_target_height_; }
[email protected]1c89c2902011-04-02 22:47:3699
100 // Platforms may optionally override these if they need to do work during
101 // processing of the given calls.
[email protected]ee574402011-06-21 17:49:35102 virtual void PlatformSpecificShow(bool animate) {}
[email protected]1c89c2902011-04-02 22:47:36103 virtual void PlatformSpecificHide(bool animate) {}
[email protected]f77c7bd62011-09-23 23:30:25104 virtual void PlatformSpecificOnCloseSoon() {}
[email protected]2a28dc22011-04-20 06:25:10105 virtual void PlatformSpecificOnHeightsRecalculated() {}
[email protected]6c6614f12011-03-31 18:51:42106
107 private:
108 // ui::AnimationDelegate:
109 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
110
[email protected]ee120872011-04-15 01:37:06111 // Finds the new desired arrow and bar heights, and if they differ from the
[email protected]4f2d40d2011-05-05 01:33:30112 // 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]cb9cf342011-04-08 01:21:09116
[email protected]6c6614f12011-03-31 18:51:42117 // 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]95a33ed62011-09-30 15:07:08122 InfoBarTabHelper* owner_;
[email protected]6c6614f12011-03-31 18:51:42123 InfoBarDelegate* delegate_;
124 InfoBarContainer* container_;
[email protected]1a53f542011-06-22 20:02:05125 ui::SlideAnimation animation_;
[email protected]6c6614f12011-03-31 18:51:42126
[email protected]2a28dc22011-04-20 06:25:10127 // 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]cb9cf342011-04-08 01:21:09134 int bar_target_height_;
135
[email protected]6c6614f12011-03-31 18:51:42136 DISALLOW_COPY_AND_ASSIGN(InfoBar);
137};
138
[email protected]c31f84b2011-06-02 21:41:34139#elif defined(OS_MACOSX)
140#include "chrome/browser/ui/cocoa/infobars/infobar.h"
141#endif
[email protected]c3217be52011-06-07 21:14:03142
[email protected]95a33ed62011-09-30 15:07:08143#endif // CHROME_BROWSER_INFOBARS_INFOBAR_H_