Chromium Code Reviews| 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/infobars/infobar_view.h" | 5 #include "chrome/browser/ui/views/infobars/infobar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/tab_contents/infobar_delegate.h" | 11 #include "chrome/browser/tab_contents/infobar_delegate.h" |
| 12 #include "chrome/browser/ui/views/infobars/infobar_background.h" | 12 #include "chrome/browser/ui/views/infobars/infobar_background.h" |
| 13 #include "chrome/browser/ui/views/infobars/infobar_button_border.h" | 13 #include "chrome/browser/ui/views/infobars/infobar_button_border.h" |
| 14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 15 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
| 16 #include "grit/theme_resources_standard.h" | 16 #include "grit/theme_resources_standard.h" |
| 17 #include "third_party/skia/include/effects/SkGradientShader.h" | 17 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 18 #include "ui/base/accessibility/accessible_view_state.h" | 18 #include "ui/base/accessibility/accessible_view_state.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/canvas_skia_paint.h" | 21 #include "ui/gfx/canvas_skia_paint.h" |
| 22 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 23 #include "views/controls/button/image_button.h" | 23 #include "views/controls/button/image_button.h" |
| 24 #include "views/controls/button/menu_button.h" | 24 #include "views/controls/button/menu_button.h" |
| 25 #include "views/controls/button/text_button.h" | 25 #include "views/controls/button/text_button.h" |
| 26 #include "views/controls/image_view.h" | 26 #include "views/controls/image_view.h" |
| 27 #include "views/controls/label.h" | 27 #include "views/controls/label.h" |
| 28 #include "views/controls/link.h" | 28 #include "views/controls/link.h" |
| 29 #include "views/controls/menu/menu_model_adapter.h" | |
| 30 #include "views/controls/menu/menu_runner.h" | |
| 29 #include "views/focus/external_focus_tracker.h" | 31 #include "views/focus/external_focus_tracker.h" |
| 30 #include "views/widget/widget.h" | 32 #include "views/widget/widget.h" |
| 31 #include "views/window/non_client_view.h" | 33 #include "views/window/non_client_view.h" |
| 32 | 34 |
| 33 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
| 34 #include <shellapi.h> | 36 #include <shellapi.h> |
| 35 | 37 |
| 36 #include "base/win/win_util.h" | 38 #include "base/win/win_util.h" |
| 37 #include "base/win/windows_version.h" | 39 #include "base/win/windows_version.h" |
| 38 #include "ui/base/win/hwnd_util.h" | 40 #include "ui/base/win/hwnd_util.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 int InfoBarView::EndX() const { | 284 int InfoBarView::EndX() const { |
| 283 const int kCloseButtonSpacing = 12; | 285 const int kCloseButtonSpacing = 12; |
| 284 return close_button_->x() - kCloseButtonSpacing; | 286 return close_button_->x() - kCloseButtonSpacing; |
| 285 } | 287 } |
| 286 | 288 |
| 287 const InfoBarContainer::Delegate* InfoBarView::container_delegate() const { | 289 const InfoBarContainer::Delegate* InfoBarView::container_delegate() const { |
| 288 const InfoBarContainer* infobar_container = container(); | 290 const InfoBarContainer* infobar_container = container(); |
| 289 return infobar_container ? infobar_container->delegate() : NULL; | 291 return infobar_container ? infobar_container->delegate() : NULL; |
| 290 } | 292 } |
| 291 | 293 |
| 294 views::MenuRunner::RunResult InfoBarView::RunMenuAt( | |
| 295 ui::MenuModel* menu_model, | |
| 296 views::MenuButton* button, | |
| 297 views::MenuItemView::AnchorPosition anchor) { | |
| 298 views::MenuModelAdapter adapter(menu_model); | |
| 299 gfx::Point screen_point; | |
| 300 views::View::ConvertPointToScreen(button, &screen_point); | |
| 301 menu_runner_.reset(new views::MenuRunner(adapter.CreateMenu())); | |
| 302 return menu_runner_->RunMenuAt( | |
| 303 GetWidget(), button, gfx::Rect(screen_point, button->size()), anchor, | |
| 304 views::MenuRunner::HAS_MNEMONICS); | |
| 305 } | |
| 306 | |
| 292 void InfoBarView::PlatformSpecificShow(bool animate) { | 307 void InfoBarView::PlatformSpecificShow(bool animate) { |
| 293 views::Widget* widget = GetWidget(); | 308 views::Widget* widget = GetWidget(); |
| 294 views::FocusManager* focus_manager = GetFocusManager(); | 309 views::FocusManager* focus_manager = GetFocusManager(); |
| 295 #if defined(OS_WIN) | 310 #if defined(OS_WIN) |
| 296 // If we gain focus, we want to restore it to the previously-focused element | 311 // If we gain focus, we want to restore it to the previously-focused element |
| 297 // when we're hidden. So when we're in a Widget, create a focus tracker so | 312 // when we're hidden. So when we're in a Widget, create a focus tracker so |
| 298 // that if we gain focus we'll know what the previously-focused element was. | 313 // that if we gain focus we'll know what the previously-focused element was. |
| 299 if (widget) { | 314 if (widget) { |
| 300 focus_tracker_.reset( | 315 focus_tracker_.reset( |
| 301 new views::ExternalFocusTracker(this, focus_manager)); | 316 new views::ExternalFocusTracker(this, focus_manager)); |
| 302 } | 317 } |
| 303 #endif | 318 #endif |
| 304 if (focus_manager) | 319 if (focus_manager) |
| 305 focus_manager->AddFocusChangeListener(this); | 320 focus_manager->AddFocusChangeListener(this); |
| 306 if (widget) { | 321 if (widget) { |
| 307 widget->NotifyAccessibilityEvent( | 322 widget->NotifyAccessibilityEvent( |
| 308 this, ui::AccessibilityTypes::EVENT_ALERT, true); | 323 this, ui::AccessibilityTypes::EVENT_ALERT, true); |
| 309 } | 324 } |
| 310 } | 325 } |
| 311 | 326 |
| 312 void InfoBarView::PlatformSpecificHide(bool animate) { | 327 void InfoBarView::PlatformSpecificHide(bool animate) { |
| 328 // We're being removed. Cancel any menus we may have open. Because we are | |
| 329 // deleted after a delay and after our delegate is deleted we have to | |
| 330 // explicitly cancel the menu rather than relying on the destructor to cancel | |
| 331 // the menu. | |
|
Peter Kasting
2011/09/15 21:43:12
Nit: Please add:
// TODO(pkasting): Remove this w
| |
| 332 menu_runner_.reset(); | |
| 333 | |
| 313 // It's possible to be called twice (once with |animate| true and once with it | 334 // It's possible to be called twice (once with |animate| true and once with it |
| 314 // false); in this case the second RemoveFocusChangeListener() call will | 335 // false); in this case the second RemoveFocusChangeListener() call will |
| 315 // silently no-op. | 336 // silently no-op. |
| 316 views::FocusManager* focus_manager = GetFocusManager(); | 337 views::FocusManager* focus_manager = GetFocusManager(); |
| 317 if (focus_manager) | 338 if (focus_manager) |
| 318 focus_manager->RemoveFocusChangeListener(this); | 339 focus_manager->RemoveFocusChangeListener(this); |
| 319 | 340 |
| 320 #if defined(OS_WIN) && !defined(USE_AURA) | 341 #if defined(OS_WIN) && !defined(USE_AURA) |
| 321 if (!animate || !focus_tracker_.get()) | 342 if (!animate || !focus_tracker_.get()) |
| 322 return; | 343 return; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 351 | 372 |
| 352 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { | 373 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { |
| 353 // This will trigger some screen readers to read the entire contents of this | 374 // This will trigger some screen readers to read the entire contents of this |
| 354 // infobar. | 375 // infobar. |
| 355 if (focused_before && focused_now && !Contains(focused_before) && | 376 if (focused_before && focused_now && !Contains(focused_before) && |
| 356 Contains(focused_now) && GetWidget()) { | 377 Contains(focused_now) && GetWidget()) { |
| 357 GetWidget()->NotifyAccessibilityEvent( | 378 GetWidget()->NotifyAccessibilityEvent( |
| 358 this, ui::AccessibilityTypes::EVENT_ALERT, true); | 379 this, ui::AccessibilityTypes::EVENT_ALERT, true); |
| 359 } | 380 } |
| 360 } | 381 } |
| OLD | NEW |