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 "chrome/browser/ui/views/bubble/bubble.h" | 5 #include "chrome/browser/ui/views/bubble/bubble.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "chrome/browser/ui/views/bubble/border_contents.h" | 9 #include "chrome/browser/ui/views/bubble/border_contents.h" |
10 #include "content/common/notification_service.h" | 10 #include "content/common/notification_service.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 // static | 49 // static |
50 Bubble* Bubble::Show(views::Widget* parent, | 50 Bubble* Bubble::Show(views::Widget* parent, |
51 const gfx::Rect& position_relative_to, | 51 const gfx::Rect& position_relative_to, |
52 BubbleBorder::ArrowLocation arrow_location, | 52 BubbleBorder::ArrowLocation arrow_location, |
53 views::View* contents, | 53 views::View* contents, |
54 BubbleDelegate* delegate) { | 54 BubbleDelegate* delegate) { |
55 Bubble* bubble = new Bubble; | 55 Bubble* bubble = new Bubble; |
56 bubble->InitBubble(parent, position_relative_to, arrow_location, | 56 bubble->InitBubble(parent, position_relative_to, arrow_location, |
57 contents, delegate); | 57 contents, delegate); |
| 58 |
| 59 // Register the Escape accelerator for closing. |
| 60 bubble->RegisterEscapeAccelerator(); |
| 61 |
58 return bubble; | 62 return bubble; |
59 } | 63 } |
60 | 64 |
61 #if defined(OS_CHROMEOS) | 65 #if defined(OS_CHROMEOS) |
62 // static | 66 // static |
63 Bubble* Bubble::ShowFocusless( | 67 Bubble* Bubble::ShowFocusless( |
64 views::Widget* parent, | 68 views::Widget* parent, |
65 const gfx::Rect& position_relative_to, | 69 const gfx::Rect& position_relative_to, |
66 BubbleBorder::ArrowLocation arrow_location, | 70 BubbleBorder::ArrowLocation arrow_location, |
67 views::View* contents, | 71 views::View* contents, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 delegate_(NULL), | 136 delegate_(NULL), |
133 show_status_(kOpen), | 137 show_status_(kOpen), |
134 fade_away_on_close_(false), | 138 fade_away_on_close_(false), |
135 #if defined(TOOLKIT_USES_GTK) | 139 #if defined(TOOLKIT_USES_GTK) |
136 type_(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS), | 140 type_(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS), |
137 #endif | 141 #endif |
138 #if defined(OS_CHROMEOS) | 142 #if defined(OS_CHROMEOS) |
139 show_while_screen_is_locked_(false), | 143 show_while_screen_is_locked_(false), |
140 #endif | 144 #endif |
141 arrow_location_(BubbleBorder::NONE), | 145 arrow_location_(BubbleBorder::NONE), |
142 contents_(NULL) { | 146 contents_(NULL), |
| 147 accelerator_registered_(false) { |
143 } | 148 } |
144 | 149 |
145 #if defined(OS_CHROMEOS) | 150 #if defined(OS_CHROMEOS) |
146 Bubble::Bubble(views::Widget::InitParams::Type type, | 151 Bubble::Bubble(views::Widget::InitParams::Type type, |
147 bool show_while_screen_is_locked) | 152 bool show_while_screen_is_locked) |
148 : views::NativeWidgetGtk(new views::Widget), | 153 : views::NativeWidgetGtk(new views::Widget), |
149 border_contents_(NULL), | 154 border_contents_(NULL), |
150 delegate_(NULL), | 155 delegate_(NULL), |
151 show_status_(kOpen), | 156 show_status_(kOpen), |
152 fade_away_on_close_(false), | 157 fade_away_on_close_(false), |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 contents_view->AddChildViewAt(border_contents_, 0); | 265 contents_view->AddChildViewAt(border_contents_, 0); |
261 | 266 |
262 // |contents_view| has no layout manager, so we have to explicitly position | 267 // |contents_view| has no layout manager, so we have to explicitly position |
263 // its children. | 268 // its children. |
264 border_contents_->SetBoundsRect( | 269 border_contents_->SetBoundsRect( |
265 gfx::Rect(gfx::Point(), window_bounds.size())); | 270 gfx::Rect(gfx::Point(), window_bounds.size())); |
266 contents->SetBoundsRect(contents_bounds); | 271 contents->SetBoundsRect(contents_bounds); |
267 #endif | 272 #endif |
268 GetWidget()->SetBounds(window_bounds); | 273 GetWidget()->SetBounds(window_bounds); |
269 | 274 |
270 // Register the Escape accelerator for closing. | |
271 GetWidget()->GetFocusManager()->RegisterAccelerator( | |
272 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); | |
273 | |
274 // Done creating the bubble. | 275 // Done creating the bubble. |
275 NotificationService::current()->Notify(NotificationType::INFO_BUBBLE_CREATED, | 276 NotificationService::current()->Notify(NotificationType::INFO_BUBBLE_CREATED, |
276 Source<Bubble>(this), | 277 Source<Bubble>(this), |
277 NotificationService::NoDetails()); | 278 NotificationService::NoDetails()); |
278 | 279 |
279 // Show the window. | 280 // Show the window. |
280 #if defined(OS_WIN) | 281 #if defined(OS_WIN) |
281 border_->ShowWindow(SW_SHOW); | 282 border_->ShowWindow(SW_SHOW); |
282 ShowWindow(SW_SHOW); | 283 ShowWindow(SW_SHOW); |
283 if (fade_in) | 284 if (fade_in) |
284 FadeIn(); | 285 FadeIn(); |
285 #elif defined(TOOLKIT_USES_GTK) | 286 #elif defined(TOOLKIT_USES_GTK) |
286 GetWidget()->Show(); | 287 GetWidget()->Show(); |
287 #endif | 288 #endif |
288 } | 289 } |
289 | 290 |
| 291 void Bubble::RegisterEscapeAccelerator() { |
| 292 GetWidget()->GetFocusManager()->RegisterAccelerator( |
| 293 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); |
| 294 accelerator_registered_ = true; |
| 295 } |
| 296 |
| 297 void Bubble::UnregisterEscapeAccelerator() { |
| 298 DCHECK(accelerator_registered_); |
| 299 GetWidget()->GetFocusManager()->UnregisterAccelerator( |
| 300 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); |
| 301 accelerator_registered_ = false; |
| 302 } |
| 303 |
290 BorderContents* Bubble::CreateBorderContents() { | 304 BorderContents* Bubble::CreateBorderContents() { |
291 return new BorderContents(); | 305 return new BorderContents(); |
292 } | 306 } |
293 | 307 |
294 void Bubble::SizeToContents() { | 308 void Bubble::SizeToContents() { |
295 gfx::Rect window_bounds; | 309 gfx::Rect window_bounds; |
296 | 310 |
297 #if defined(OS_WIN) | 311 #if defined(OS_WIN) |
298 // Initialize and position the border window. | 312 // Initialize and position the border window. |
299 window_bounds = border_->SizeAndGetBounds(position_relative_to_, | 313 window_bounds = border_->SizeAndGetBounds(position_relative_to_, |
(...skipping 27 matching lines...) Expand all Loading... |
327 void Bubble::IsActiveChanged() { | 341 void Bubble::IsActiveChanged() { |
328 if (!GetWidget()->IsActive()) | 342 if (!GetWidget()->IsActive()) |
329 GetWidget()->Close(); | 343 GetWidget()->Close(); |
330 } | 344 } |
331 #endif | 345 #endif |
332 | 346 |
333 void Bubble::DoClose(bool closed_by_escape) { | 347 void Bubble::DoClose(bool closed_by_escape) { |
334 if (show_status_ == kClosed) | 348 if (show_status_ == kClosed) |
335 return; | 349 return; |
336 | 350 |
337 GetWidget()->GetFocusManager()->UnregisterAccelerator( | 351 if (accelerator_registered_) |
338 views::Accelerator(ui::VKEY_ESCAPE, false, false, false), this); | 352 UnregisterEscapeAccelerator(); |
339 if (delegate_) | 353 if (delegate_) |
340 delegate_->BubbleClosing(this, closed_by_escape); | 354 delegate_->BubbleClosing(this, closed_by_escape); |
341 show_status_ = kClosed; | 355 show_status_ = kClosed; |
342 #if defined(OS_WIN) | 356 #if defined(OS_WIN) |
343 border_->Close(); | 357 border_->Close(); |
344 #endif | 358 #endif |
345 #if defined(OS_WIN) | 359 #if defined(OS_WIN) |
346 NativeWidgetWin::Close(); | 360 NativeWidgetWin::Close(); |
347 #elif defined(TOOLKIT_USES_GTK) | 361 #elif defined(TOOLKIT_USES_GTK) |
348 NativeWidgetGtk::Close(); | 362 NativeWidgetGtk::Close(); |
(...skipping 30 matching lines...) Expand all Loading... |
379 animation_->Hide(); | 393 animation_->Hide(); |
380 } | 394 } |
381 | 395 |
382 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { | 396 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { |
383 if (!delegate_ || delegate_->CloseOnEscape()) { | 397 if (!delegate_ || delegate_->CloseOnEscape()) { |
384 DoClose(true); | 398 DoClose(true); |
385 return true; | 399 return true; |
386 } | 400 } |
387 return false; | 401 return false; |
388 } | 402 } |
OLD | NEW |