| 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 "chrome/common/chrome_notification_types.h" | 10 #include "chrome/common/chrome_notification_types.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 string16 BubbleDelegate::GetAccessibleName() { | 44 string16 BubbleDelegate::GetAccessibleName() { |
| 45 return string16(); | 45 return string16(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Bubble ----------------------------------------------------------------- | 48 // Bubble ----------------------------------------------------------------- |
| 49 | 49 |
| 50 // static | 50 // static |
| 51 Bubble* Bubble::Show(views::Widget* parent, | 51 Bubble* Bubble::Show(views::Widget* parent, |
| 52 const gfx::Rect& position_relative_to, | 52 const gfx::Rect& position_relative_to, |
| 53 views::BubbleBorder::ArrowLocation arrow_location, | 53 views::BubbleBorder::ArrowLocation arrow_location, |
| 54 views::BubbleBorder::BubbleAlignment alignment, |
| 54 views::View* contents, | 55 views::View* contents, |
| 55 BubbleDelegate* delegate) { | 56 BubbleDelegate* delegate) { |
| 56 Bubble* bubble = new Bubble; | 57 Bubble* bubble = new Bubble; |
| 57 bubble->InitBubble(parent, position_relative_to, arrow_location, | 58 bubble->InitBubble(parent, position_relative_to, arrow_location, alignment, |
| 58 contents, delegate); | 59 contents, delegate); |
| 59 | 60 |
| 60 // Register the Escape accelerator for closing. | 61 // Register the Escape accelerator for closing. |
| 61 bubble->RegisterEscapeAccelerator(); | 62 bubble->RegisterEscapeAccelerator(); |
| 62 | 63 |
| 63 if (delegate) | 64 if (delegate) |
| 64 delegate->BubbleShown(); | 65 delegate->BubbleShown(); |
| 65 | 66 |
| 66 return bubble; | 67 return bubble; |
| 67 } | 68 } |
| 68 | 69 |
| 69 #if defined(OS_CHROMEOS) | 70 #if defined(OS_CHROMEOS) |
| 70 // static | 71 // static |
| 71 Bubble* Bubble::ShowFocusless( | 72 Bubble* Bubble::ShowFocusless( |
| 72 views::Widget* parent, | 73 views::Widget* parent, |
| 73 const gfx::Rect& position_relative_to, | 74 const gfx::Rect& position_relative_to, |
| 74 views::BubbleBorder::ArrowLocation arrow_location, | 75 views::BubbleBorder::ArrowLocation arrow_location, |
| 76 views::BubbleBorder::BubbleAlignment alignment, |
| 75 views::View* contents, | 77 views::View* contents, |
| 76 BubbleDelegate* delegate, | 78 BubbleDelegate* delegate, |
| 77 bool show_while_screen_is_locked) { | 79 bool show_while_screen_is_locked) { |
| 78 Bubble* bubble = new Bubble(views::Widget::InitParams::TYPE_POPUP, | 80 Bubble* bubble = new Bubble(views::Widget::InitParams::TYPE_POPUP, |
| 79 show_while_screen_is_locked); | 81 show_while_screen_is_locked); |
| 80 bubble->InitBubble(parent, position_relative_to, arrow_location, | 82 bubble->InitBubble(parent, position_relative_to, arrow_location, alignment, |
| 81 contents, delegate); | 83 contents, delegate); |
| 82 return bubble; | 84 return bubble; |
| 83 } | 85 } |
| 84 #endif | 86 #endif |
| 85 | 87 |
| 86 void Bubble::Close() { | 88 void Bubble::Close() { |
| 87 if (show_status_ != kOpen) | 89 if (show_status_ != kOpen) |
| 88 return; | 90 return; |
| 89 | 91 |
| 90 show_status_ = kClosing; | 92 show_status_ = kClosing; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 contents_(NULL) { | 186 contents_(NULL) { |
| 185 } | 187 } |
| 186 #endif | 188 #endif |
| 187 | 189 |
| 188 Bubble::~Bubble() { | 190 Bubble::~Bubble() { |
| 189 } | 191 } |
| 190 | 192 |
| 191 void Bubble::InitBubble(views::Widget* parent, | 193 void Bubble::InitBubble(views::Widget* parent, |
| 192 const gfx::Rect& position_relative_to, | 194 const gfx::Rect& position_relative_to, |
| 193 views::BubbleBorder::ArrowLocation arrow_location, | 195 views::BubbleBorder::ArrowLocation arrow_location, |
| 196 views::BubbleBorder::BubbleAlignment alignment, |
| 194 views::View* contents, | 197 views::View* contents, |
| 195 BubbleDelegate* delegate) { | 198 BubbleDelegate* delegate) { |
| 196 delegate_ = delegate; | 199 delegate_ = delegate; |
| 197 position_relative_to_ = position_relative_to; | 200 position_relative_to_ = position_relative_to; |
| 198 arrow_location_ = arrow_location; | 201 arrow_location_ = arrow_location; |
| 199 contents_ = contents; | 202 contents_ = contents; |
| 200 const bool fade_in = delegate_ && delegate_->FadeInOnShow(); | 203 const bool fade_in = delegate_ && delegate_->FadeInOnShow(); |
| 201 | 204 |
| 202 // Create the main window. | 205 // Create the main window. |
| 203 #if defined(USE_AURA) | 206 #if defined(USE_AURA) |
| 204 // TODO(beng): | 207 // TODO(beng): |
| 205 NOTIMPLEMENTED(); | 208 NOTIMPLEMENTED(); |
| 206 #elif defined(OS_WIN) | 209 #elif defined(OS_WIN) |
| 207 views::Widget* parent_window = parent->GetTopLevelWidget(); | 210 views::Widget* parent_window = parent->GetTopLevelWidget(); |
| 208 if (parent_window) | 211 if (parent_window) |
| 209 parent_window->DisableInactiveRendering(); | 212 parent_window->DisableInactiveRendering(); |
| 210 set_window_style(WS_POPUP | WS_CLIPCHILDREN); | 213 set_window_style(WS_POPUP | WS_CLIPCHILDREN); |
| 211 int extended_style = WS_EX_TOOLWINDOW; | 214 int extended_style = WS_EX_TOOLWINDOW; |
| 212 // During FadeIn we need to turn on the layered window style to deal with | 215 // During FadeIn we need to turn on the layered window style to deal with |
| 213 // transparency. This flag needs to be reset after fading in is complete. | 216 // transparency. This flag needs to be reset after fading in is complete. |
| 214 if (fade_in) | 217 if (fade_in) |
| 215 extended_style |= WS_EX_LAYERED; | 218 extended_style |= WS_EX_LAYERED; |
| 216 set_window_ex_style(extended_style); | 219 set_window_ex_style(extended_style); |
| 217 | 220 |
| 218 DCHECK(!border_); | 221 DCHECK(!border_); |
| 219 border_ = new BorderWidgetWin(); | 222 border_ = new BorderWidgetWin(); |
| 220 | 223 |
| 221 border_->InitBorderWidgetWin(CreateBorderContents(), parent->GetNativeView()); | 224 border_->InitBorderWidgetWin(CreateBorderContents(), parent->GetNativeView()); |
| 222 border_->border_contents()->SetBackgroundColor(kBackgroundColor); | 225 border_->border_contents()->SetBackgroundColor(kBackgroundColor); |
| 226 border_->border_contents()->SetAlignment(alignment); |
| 223 | 227 |
| 224 // We make the BorderWidgetWin the owner of the Bubble HWND, so that the | 228 // We make the BorderWidgetWin the owner of the Bubble HWND, so that the |
| 225 // latter is displayed on top of the former. | 229 // latter is displayed on top of the former. |
| 226 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 230 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
| 227 params.parent = border_->GetNativeView(); | 231 params.parent = border_->GetNativeView(); |
| 228 params.native_widget = this; | 232 params.native_widget = this; |
| 229 GetWidget()->Init(params); | 233 GetWidget()->Init(params); |
| 230 | 234 |
| 231 if (fade_in) { | 235 if (fade_in) { |
| 232 border_->SetOpacity(0); | 236 border_->SetOpacity(0); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 contents_view->SetLayoutManager(new views::FillLayout); | 285 contents_view->SetLayoutManager(new views::FillLayout); |
| 282 | 286 |
| 283 // Paint the background color behind the contents. | 287 // Paint the background color behind the contents. |
| 284 contents_view->set_background( | 288 contents_view->set_background( |
| 285 views::Background::CreateSolidBackground(kBackgroundColor)); | 289 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 286 #else | 290 #else |
| 287 // Create a view to paint the border and background. | 291 // Create a view to paint the border and background. |
| 288 border_contents_ = CreateBorderContents(); | 292 border_contents_ = CreateBorderContents(); |
| 289 border_contents_->Init(); | 293 border_contents_->Init(); |
| 290 border_contents_->SetBackgroundColor(kBackgroundColor); | 294 border_contents_->SetBackgroundColor(kBackgroundColor); |
| 295 border_contents_->SetAlignment(alignment); |
| 291 gfx::Rect contents_bounds; | 296 gfx::Rect contents_bounds; |
| 292 border_contents_->SizeAndGetBounds(position_relative_to, | 297 border_contents_->SizeAndGetBounds(position_relative_to, |
| 293 arrow_location, false, contents->GetPreferredSize(), | 298 arrow_location, false, contents->GetPreferredSize(), |
| 294 &contents_bounds, &window_bounds); | 299 &contents_bounds, &window_bounds); |
| 295 // This new view must be added before |contents| so it will paint under it. | 300 // This new view must be added before |contents| so it will paint under it. |
| 296 contents_view->AddChildViewAt(border_contents_, 0); | 301 contents_view->AddChildViewAt(border_contents_, 0); |
| 297 | 302 |
| 298 // |contents_view| has no layout manager, so we have to explicitly position | 303 // |contents_view| has no layout manager, so we have to explicitly position |
| 299 // its children. | 304 // its children. |
| 300 border_contents_->SetBoundsRect( | 305 border_contents_->SetBoundsRect( |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 animation_->Hide(); | 449 animation_->Hide(); |
| 445 } | 450 } |
| 446 | 451 |
| 447 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { | 452 bool Bubble::AcceleratorPressed(const views::Accelerator& accelerator) { |
| 448 if (!delegate_ || delegate_->CloseOnEscape()) { | 453 if (!delegate_ || delegate_->CloseOnEscape()) { |
| 449 DoClose(true); | 454 DoClose(true); |
| 450 return true; | 455 return true; |
| 451 } | 456 } |
| 452 return false; | 457 return false; |
| 453 } | 458 } |
| OLD | NEW |