OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/views/bubble/bubble_delegate.h" | 5 #include "ui/views/bubble/bubble_delegate.h" |
6 | 6 |
7 #include "ui/base/animation/slide_animation.h" | 7 #include "ui/base/animation/slide_animation.h" |
8 #include "ui/gfx/color_utils.h" | 8 #include "ui/gfx/color_utils.h" |
9 #include "ui/views/bubble/bubble_frame_view.h" | 9 #include "ui/views/bubble/bubble_frame_view.h" |
10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
| 11 #include "ui/views/widget/widget_observer.h" |
11 | 12 |
12 // The duration of the fade animation in milliseconds. | 13 // The duration of the fade animation in milliseconds. |
13 static const int kHideFadeDurationMS = 200; | 14 static const int kHideFadeDurationMS = 200; |
14 | 15 |
15 // The defaut margin between the content and the inside border, in pixels. | 16 // The defaut margin between the content and the inside border, in pixels. |
16 static const int kDefaultMargin = 6; | 17 static const int kDefaultMargin = 6; |
17 | 18 |
18 namespace views { | 19 namespace views { |
19 | 20 |
20 namespace { | 21 namespace { |
(...skipping 16 matching lines...) Expand all Loading... |
37 #endif | 38 #endif |
38 bubble_widget->Init(bubble_params); | 39 bubble_widget->Init(bubble_params); |
39 return bubble_widget; | 40 return bubble_widget; |
40 } | 41 } |
41 | 42 |
42 #if defined(OS_WIN) && !defined(USE_AURA) | 43 #if defined(OS_WIN) && !defined(USE_AURA) |
43 // Windows uses two widgets and some extra complexity to host partially | 44 // Windows uses two widgets and some extra complexity to host partially |
44 // transparent native controls and use per-pixel HWND alpha on the border. | 45 // transparent native controls and use per-pixel HWND alpha on the border. |
45 // TODO(msw): Clean these up when Windows native controls are no longer needed. | 46 // TODO(msw): Clean these up when Windows native controls are no longer needed. |
46 class BubbleBorderDelegate : public WidgetDelegate, | 47 class BubbleBorderDelegate : public WidgetDelegate, |
47 public Widget::Observer { | 48 public WidgetObserver { |
48 public: | 49 public: |
49 BubbleBorderDelegate(BubbleDelegateView* bubble, Widget* widget) | 50 BubbleBorderDelegate(BubbleDelegateView* bubble, Widget* widget) |
50 : bubble_(bubble), | 51 : bubble_(bubble), |
51 widget_(widget) { | 52 widget_(widget) { |
52 bubble_->GetWidget()->AddObserver(this); | 53 bubble_->GetWidget()->AddObserver(this); |
53 } | 54 } |
54 | 55 |
55 virtual ~BubbleBorderDelegate() { | 56 virtual ~BubbleBorderDelegate() { |
56 if (bubble_ && bubble_->GetWidget()) | 57 if (bubble_ && bubble_->GetWidget()) |
57 bubble_->GetWidget()->RemoveObserver(this); | 58 bubble_->GetWidget()->RemoveObserver(this); |
58 } | 59 } |
59 | 60 |
60 // WidgetDelegate overrides: | 61 // WidgetDelegate overrides: |
61 virtual bool CanActivate() const OVERRIDE { return false; } | 62 virtual bool CanActivate() const OVERRIDE { return false; } |
62 virtual void DeleteDelegate() OVERRIDE { delete this; } | 63 virtual void DeleteDelegate() OVERRIDE { delete this; } |
63 virtual Widget* GetWidget() OVERRIDE { return widget_; } | 64 virtual Widget* GetWidget() OVERRIDE { return widget_; } |
64 virtual const Widget* GetWidget() const OVERRIDE { return widget_; } | 65 virtual const Widget* GetWidget() const OVERRIDE { return widget_; } |
65 virtual NonClientFrameView* CreateNonClientFrameView( | 66 virtual NonClientFrameView* CreateNonClientFrameView( |
66 views::Widget* widget) OVERRIDE { | 67 Widget* widget) OVERRIDE { |
67 return bubble_->CreateNonClientFrameView(widget); | 68 return bubble_->CreateNonClientFrameView(widget); |
68 } | 69 } |
69 | 70 |
70 // Widget::Observer overrides: | 71 // WidgetObserver overrides: |
71 virtual void OnWidgetClosing(Widget* widget) OVERRIDE { | 72 virtual void OnWidgetClosing(Widget* widget) OVERRIDE { |
72 bubble_ = NULL; | 73 bubble_ = NULL; |
73 widget_->Close(); | 74 widget_->Close(); |
74 } | 75 } |
75 | 76 |
76 private: | 77 private: |
77 BubbleDelegateView* bubble_; | 78 BubbleDelegateView* bubble_; |
78 Widget* widget_; | 79 Widget* widget_; |
79 | 80 |
80 DISALLOW_COPY_AND_ASSIGN(BubbleBorderDelegate); | 81 DISALLOW_COPY_AND_ASSIGN(BubbleBorderDelegate); |
(...skipping 27 matching lines...) Expand all Loading... |
108 anchor_view_(NULL), | 109 anchor_view_(NULL), |
109 anchor_widget_(NULL), | 110 anchor_widget_(NULL), |
110 move_with_anchor_(false), | 111 move_with_anchor_(false), |
111 arrow_location_(BubbleBorder::TOP_LEFT), | 112 arrow_location_(BubbleBorder::TOP_LEFT), |
112 color_(kBackgroundColor), | 113 color_(kBackgroundColor), |
113 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 114 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
114 original_opacity_(255), | 115 original_opacity_(255), |
115 border_widget_(NULL), | 116 border_widget_(NULL), |
116 use_focusless_(false), | 117 use_focusless_(false), |
117 parent_window_(NULL) { | 118 parent_window_(NULL) { |
118 set_background(views::Background::CreateSolidBackground(color_)); | 119 set_background(Background::CreateSolidBackground(color_)); |
119 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 120 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
120 } | 121 } |
121 | 122 |
122 BubbleDelegateView::BubbleDelegateView( | 123 BubbleDelegateView::BubbleDelegateView( |
123 View* anchor_view, | 124 View* anchor_view, |
124 BubbleBorder::ArrowLocation arrow_location) | 125 BubbleBorder::ArrowLocation arrow_location) |
125 : close_on_esc_(true), | 126 : close_on_esc_(true), |
126 close_on_deactivate_(true), | 127 close_on_deactivate_(true), |
127 anchor_view_(anchor_view), | 128 anchor_view_(anchor_view), |
128 anchor_widget_(NULL), | 129 anchor_widget_(NULL), |
129 move_with_anchor_(false), | 130 move_with_anchor_(false), |
130 arrow_location_(arrow_location), | 131 arrow_location_(arrow_location), |
131 color_(kBackgroundColor), | 132 color_(kBackgroundColor), |
132 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 133 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
133 original_opacity_(255), | 134 original_opacity_(255), |
134 border_widget_(NULL), | 135 border_widget_(NULL), |
135 use_focusless_(false), | 136 use_focusless_(false), |
136 parent_window_(NULL) { | 137 parent_window_(NULL) { |
137 set_background(views::Background::CreateSolidBackground(color_)); | 138 set_background(Background::CreateSolidBackground(color_)); |
138 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 139 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
139 } | 140 } |
140 | 141 |
141 BubbleDelegateView::~BubbleDelegateView() { | 142 BubbleDelegateView::~BubbleDelegateView() { |
142 if (anchor_widget() != NULL) | 143 if (anchor_widget() != NULL) |
143 anchor_widget()->RemoveObserver(this); | 144 anchor_widget()->RemoveObserver(this); |
144 anchor_widget_ = NULL; | 145 anchor_widget_ = NULL; |
145 anchor_view_ = NULL; | 146 anchor_view_ = NULL; |
146 } | 147 } |
147 | 148 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 328 |
328 #if defined(OS_WIN) && !defined(USE_AURA) | 329 #if defined(OS_WIN) && !defined(USE_AURA) |
329 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 330 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
330 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 331 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
331 client_bounds.Offset(border_widget_->GetWindowBoundsInScreen().origin()); | 332 client_bounds.Offset(border_widget_->GetWindowBoundsInScreen().origin()); |
332 return client_bounds; | 333 return client_bounds; |
333 } | 334 } |
334 #endif | 335 #endif |
335 | 336 |
336 } // namespace views | 337 } // namespace views |
OLD | NEW |