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 #include "views/bubble/bubble_delegate.h" | 5 #include "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 "views/bubble/bubble_frame_view.h" | 8 #include "views/bubble/bubble_frame_view.h" |
9 #include "views/widget/widget.h" | 9 #include "views/widget/widget.h" |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 border_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 68 border_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
69 border_widget->Init(border_params); | 69 border_widget->Init(border_params); |
70 return border_widget; | 70 return border_widget; |
71 } | 71 } |
72 #endif | 72 #endif |
73 | 73 |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 BubbleDelegateView::BubbleDelegateView() | 76 BubbleDelegateView::BubbleDelegateView() |
77 : close_on_esc_(true), | 77 : close_on_esc_(true), |
78 close_on_blur_(true), | |
78 arrow_location_(BubbleBorder::TOP_LEFT), | 79 arrow_location_(BubbleBorder::TOP_LEFT), |
79 color_(SK_ColorWHITE), | 80 color_(SK_ColorWHITE), |
80 border_widget_(NULL) { | 81 border_widget_(NULL) { |
81 set_background(views::Background::CreateSolidBackground(color_)); | 82 set_background(views::Background::CreateSolidBackground(color_)); |
82 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); | 83 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); |
83 } | 84 } |
84 | 85 |
85 BubbleDelegateView::BubbleDelegateView( | 86 BubbleDelegateView::BubbleDelegateView( |
86 const gfx::Point& anchor_point, | 87 const gfx::Point& anchor_point, |
87 BubbleBorder::ArrowLocation arrow_location, | 88 BubbleBorder::ArrowLocation arrow_location, |
88 const SkColor& color) | 89 const SkColor& color) |
89 : close_on_esc_(true), | 90 : close_on_esc_(true), |
91 close_on_blur_(true), | |
90 anchor_point_(anchor_point), | 92 anchor_point_(anchor_point), |
91 arrow_location_(arrow_location), | 93 arrow_location_(arrow_location), |
92 color_(color), | 94 color_(color), |
93 original_opacity_(255), | 95 original_opacity_(255), |
94 border_widget_(NULL) { | 96 border_widget_(NULL) { |
95 set_background(views::Background::CreateSolidBackground(color_)); | 97 set_background(views::Background::CreateSolidBackground(color_)); |
96 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); | 98 AddAccelerator(Accelerator(ui::VKEY_ESCAPE, 0)); |
97 } | 99 } |
98 | 100 |
99 BubbleDelegateView::~BubbleDelegateView() { | 101 BubbleDelegateView::~BubbleDelegateView() { |
100 if (border_widget_) | 102 if (border_widget_) |
101 border_widget_->Close(); | 103 border_widget_->Close(); |
104 WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); | |
102 } | 105 } |
103 | 106 |
104 // static | 107 // static |
105 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate, | 108 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate, |
106 Widget* parent_widget) { | 109 Widget* parent_widget) { |
107 bubble_delegate->Init(); | 110 bubble_delegate->Init(); |
108 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent_widget); | 111 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate, parent_widget); |
109 | 112 |
110 #if defined(OS_WIN) && !defined(USE_AURA) | 113 #if defined(OS_WIN) && !defined(USE_AURA) |
111 bubble_delegate->InitializeBorderWidget(parent_widget); | 114 bubble_delegate->InitializeBorderWidget(parent_widget); |
112 bubble_widget->SetContentsView(bubble_delegate->GetContentsView()); | 115 bubble_widget->SetContentsView(bubble_delegate->GetContentsView()); |
113 bubble_widget->SetBounds(bubble_delegate->GetBubbleClientBounds()); | 116 bubble_widget->SetBounds(bubble_delegate->GetBubbleClientBounds()); |
114 #else | 117 #else |
115 bubble_widget->SetBounds(bubble_delegate->GetBubbleBounds()); | 118 bubble_widget->SetBounds(bubble_delegate->GetBubbleBounds()); |
116 #endif | 119 #endif |
117 | 120 |
121 if (parent_widget && parent_widget->GetTopLevelWidget()) | |
122 parent_widget->GetTopLevelWidget()->DisableInactiveRendering(); | |
123 WidgetFocusManager::GetInstance()->AddFocusChangeListener(bubble_delegate); | |
118 return bubble_widget; | 124 return bubble_widget; |
119 } | 125 } |
120 | 126 |
121 View* BubbleDelegateView::GetInitiallyFocusedView() { | 127 View* BubbleDelegateView::GetInitiallyFocusedView() { |
122 return this; | 128 return this; |
123 } | 129 } |
124 | 130 |
125 View* BubbleDelegateView::GetContentsView() { | 131 View* BubbleDelegateView::GetContentsView() { |
126 return this; | 132 return this; |
127 } | 133 } |
128 | 134 |
129 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() { | 135 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView() { |
130 return new BubbleFrameView(GetArrowLocation(), | 136 return new BubbleFrameView(GetArrowLocation(), |
131 GetPreferredSize(), | 137 GetPreferredSize(), |
132 GetColor()); | 138 GetColor()); |
133 } | 139 } |
134 | 140 |
141 void BubbleDelegateView::NativeFocusWillChange(gfx::NativeView focused_before, | |
142 gfx::NativeView focused_now) { | |
143 if (close_on_blur()) { | |
144 gfx::NativeView native_view = GetWidget()->GetNativeView(); | |
145 if (focused_before == native_view && focused_now != native_view) { | |
Ben Goodger (Google)
2011/11/01 23:54:56
I thought we just discussed doing this in an activ
msw
2011/11/05 03:22:24
Done.
I was lead astray by WidgetFocusChangeListe
| |
146 WidgetFocusManager::GetInstance()->RemoveFocusChangeListener(this); | |
147 GetWidget()->Close(); | |
148 } | |
149 } | |
150 } | |
151 | |
135 gfx::Point BubbleDelegateView::GetAnchorPoint() { | 152 gfx::Point BubbleDelegateView::GetAnchorPoint() { |
136 return anchor_point_; | 153 return anchor_point_; |
137 } | 154 } |
138 | 155 |
139 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { | 156 BubbleBorder::ArrowLocation BubbleDelegateView::GetArrowLocation() const { |
140 return arrow_location_; | 157 return arrow_location_; |
141 } | 158 } |
142 | 159 |
143 SkColor BubbleDelegateView::GetColor() const { | 160 SkColor BubbleDelegateView::GetColor() const { |
144 return color_; | 161 return color_; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 } | 252 } |
236 | 253 |
237 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 254 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
238 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 255 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
239 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); | 256 client_bounds.Offset(border_widget_->GetWindowScreenBounds().origin()); |
240 return client_bounds; | 257 return client_bounds; |
241 } | 258 } |
242 #endif | 259 #endif |
243 | 260 |
244 } // namespace views | 261 } // namespace views |
OLD | NEW |