OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 VIEWS_BUBBLE_BUBBLE_DELEGATE_H_ | 5 #ifndef VIEWS_BUBBLE_BUBBLE_DELEGATE_H_ |
6 #define VIEWS_BUBBLE_BUBBLE_DELEGATE_H_ | 6 #define VIEWS_BUBBLE_BUBBLE_DELEGATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/gtest_prod_util.h" | |
9 #include "ui/base/animation/animation_delegate.h" | 10 #include "ui/base/animation/animation_delegate.h" |
10 #include "views/bubble/bubble_border.h" | 11 #include "views/bubble/bubble_border.h" |
11 #include "views/widget/widget_delegate.h" | 12 #include "views/widget/widget_delegate.h" |
12 | 13 |
13 namespace ui { | 14 namespace ui { |
14 class SlideAnimation; | 15 class SlideAnimation; |
15 } // namespace ui | 16 } // namespace ui |
16 | 17 |
17 namespace views { | 18 namespace views { |
18 | 19 |
19 class BubbleFrameView; | 20 class BubbleFrameView; |
20 class BubbleView; | |
21 | 21 |
22 // BubbleDelegateView creates frame and client views for bubble Widgets. | 22 // BubbleDelegateView creates frame and client views for bubble Widgets. |
23 // BubbleDelegateView itself is the client's contents view. | 23 // BubbleDelegateView itself is the client's contents view. |
24 // | 24 // |
25 /////////////////////////////////////////////////////////////////////////////// | 25 /////////////////////////////////////////////////////////////////////////////// |
26 class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, | 26 class VIEWS_EXPORT BubbleDelegateView : public WidgetDelegateView, |
27 public ui::AnimationDelegate { | 27 public ui::AnimationDelegate { |
28 public: | 28 public: |
29 BubbleDelegateView(); | 29 BubbleDelegateView(); |
30 BubbleDelegateView(const gfx::Point& anchor_point, | 30 BubbleDelegateView(const gfx::Point& anchor_point, |
31 BubbleBorder::ArrowLocation arrow_location, | 31 BubbleBorder::ArrowLocation arrow_location, |
32 const SkColor& color); | 32 const SkColor& color); |
33 virtual ~BubbleDelegateView(); | 33 virtual ~BubbleDelegateView(); |
34 | 34 |
35 // Create a bubble Widget from the argument BubbleDelegateView. | 35 // Create and intitialize the bubble Widget(s) with proper bounds. |
Ben Goodger (Google)
2011/11/01 19:24:54
initialize
msw
2011/11/01 19:47:11
Done.
| |
36 static Widget* CreateBubble(BubbleDelegateView* bubble_delegate, | 36 static void CreateBubble(BubbleDelegateView* bubble_delegate, |
37 Widget* parent_widget); | 37 Widget* parent_widget); |
38 | 38 |
39 // WidgetDelegate overrides: | 39 // WidgetDelegate overrides: |
40 virtual View* GetInitiallyFocusedView() OVERRIDE; | 40 virtual View* GetInitiallyFocusedView() OVERRIDE; |
41 virtual View* GetContentsView() OVERRIDE; | 41 virtual View* GetContentsView() OVERRIDE; |
42 virtual ClientView* CreateClientView(Widget* widget) OVERRIDE; | |
43 virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE; | 42 virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE; |
44 | 43 |
45 bool close_on_esc() const { return close_on_esc_; } | 44 bool close_on_esc() const { return close_on_esc_; } |
46 void set_close_on_esc(bool close_on_esc) { close_on_esc_ = close_on_esc; } | 45 void set_close_on_esc(bool close_on_esc) { close_on_esc_ = close_on_esc; } |
47 | 46 |
48 // Get the arrow's anchor point in screen space. | 47 // Get the arrow's anchor point in screen space. |
49 virtual gfx::Point GetAnchorPoint(); | 48 virtual gfx::Point GetAnchorPoint(); |
50 | 49 |
51 // Get the arrow's location on the bubble. | 50 // Get the arrow's location on the bubble. |
52 virtual BubbleBorder::ArrowLocation GetArrowLocation() const; | 51 virtual BubbleBorder::ArrowLocation GetArrowLocation() const; |
53 | 52 |
54 // Get the color used for the background and border. | 53 // Get the color used for the background and border. |
55 virtual SkColor GetColor() const; | 54 virtual SkColor GetColor() const; |
56 | 55 |
56 // Show the bubble's widget (and |border_widget_| on Windows). | |
57 void Show(); | |
58 | |
57 // Fade the bubble in or out via Widget transparency. | 59 // Fade the bubble in or out via Widget transparency. |
58 // Fade in calls Widget::Show; fade out calls Widget::Close upon completion. | 60 // Fade in calls Widget::Show; fade out calls Widget::Close upon completion. |
59 void StartFade(bool fade_in); | 61 void StartFade(bool fade_in); |
60 | 62 |
61 // Reset fade and opacity of bubble. Restore the opacity of the | 63 // Reset fade and opacity of bubble. Restore the opacity of the |
62 // bubble to the setting before StartFade() was called. | 64 // bubble to the setting before StartFade() was called. |
63 void ResetFade(); | 65 void ResetFade(); |
64 | 66 |
65 protected: | 67 protected: |
66 // View overrides: | 68 // View overrides: |
67 virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; | 69 virtual bool AcceleratorPressed(const Accelerator& accelerator) OVERRIDE; |
68 | 70 |
69 // Perform view initialization on the contents for bubble sizing. | 71 // Perform view initialization on the contents for bubble sizing. |
70 virtual void Init(); | 72 virtual void Init(); |
71 | 73 |
72 private: | 74 private: |
75 FRIEND_TEST_ALL_PREFIXES(BubbleFrameViewBasicTest, NonClientHitTest); | |
76 FRIEND_TEST_ALL_PREFIXES(BubbleDelegateTest, CreateDelegate); | |
77 | |
73 // ui::AnimationDelegate overrides: | 78 // ui::AnimationDelegate overrides: |
74 virtual void AnimationEnded(const ui::Animation* animation); | 79 virtual void AnimationEnded(const ui::Animation* animation); |
75 virtual void AnimationProgressed(const ui::Animation* animation); | 80 virtual void AnimationProgressed(const ui::Animation* animation); |
76 | 81 |
77 const BubbleView* GetBubbleView() const; | 82 BubbleFrameView* GetBubbleFrameView() const; |
78 const BubbleFrameView* GetBubbleFrameView() const; | |
79 | 83 |
80 // Get bubble bounds from the anchor point and client view's preferred size. | 84 // Get bubble bounds from the anchor point and client view's preferred size. |
81 gfx::Rect GetBubbleBounds(); | 85 gfx::Rect GetBubbleBounds(); |
82 | 86 |
87 #if defined(OS_WIN) && !defined(USE_AURA) | |
88 // Initialize the border widget needed for Windows native control hosting. | |
89 void InitializeBorderWidget(Widget* parent_widget); | |
90 | |
91 // Get bounds for the Windows-only widget that hosts the bubble's contents. | |
92 gfx::Rect GetBubbleClientBounds() const; | |
93 #endif | |
94 | |
83 // Fade animation for bubble. | 95 // Fade animation for bubble. |
84 scoped_ptr<ui::SlideAnimation> fade_animation_; | 96 scoped_ptr<ui::SlideAnimation> fade_animation_; |
85 | 97 |
86 // Should this bubble close on the escape key? | 98 // Should this bubble close on the escape key? |
87 bool close_on_esc_; | 99 bool close_on_esc_; |
88 | 100 |
89 // The screen point where this bubble's arrow is anchored. | 101 // The screen point where this bubble's arrow is anchored. |
90 gfx::Point anchor_point_; | 102 gfx::Point anchor_point_; |
91 | 103 |
92 // The arrow's location on the bubble. | 104 // The arrow's location on the bubble. |
93 BubbleBorder::ArrowLocation arrow_location_; | 105 BubbleBorder::ArrowLocation arrow_location_; |
94 | 106 |
95 // The background color of the bubble. | 107 // The background color of the bubble. |
96 SkColor color_; | 108 SkColor color_; |
97 | 109 |
98 // Original opacity of the bubble. | 110 // Original opacity of the bubble. |
99 int original_opacity_; | 111 int original_opacity_; |
112 | |
113 // The widget hosting the border for this bubble (non-Aura Windows only). | |
114 Widget* border_widget_; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(BubbleDelegateView); | |
100 }; | 117 }; |
101 | 118 |
102 } // namespace views | 119 } // namespace views |
103 | 120 |
104 #endif // VIEWS_BUBBLE_BUBBLE_DELEGATE_H_ | 121 #endif // VIEWS_BUBBLE_BUBBLE_DELEGATE_H_ |
OLD | NEW |