Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/browser/ui/views/infobars/infobar_view.cc

Issue 7796010: Attempt at fixing crash in menus shown from infobars. Here's what the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ignore return value Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 void InfoBarView::RunMenuAt(ui::MenuModel* menu_model,
295 views::MenuButton* button,
296 views::MenuItemView::AnchorPosition anchor) {
297 views::MenuModelAdapter adapter(menu_model);
298 gfx::Point screen_point;
299 views::View::ConvertPointToScreen(button, &screen_point);
300 menu_runner_.reset(new views::MenuRunner(adapter.CreateMenu()));
301 // Ignore the result as we know we can only get here after the menu has
302 // closed.
Peter Kasting 2011/09/19 19:08:14 Nit: This comment is a bit confusing, partly becau
303 ignore_result(menu_runner_->RunMenuAt(
304 GetWidget(), button, gfx::Rect(screen_point, button->size()), anchor,
305 views::MenuRunner::HAS_MNEMONICS));
306 // TODO(pkasting): this may be deleted after rewrite. Update comment after
307 // rewrite as necessary.
308 }
309
292 void InfoBarView::PlatformSpecificShow(bool animate) { 310 void InfoBarView::PlatformSpecificShow(bool animate) {
293 views::Widget* widget = GetWidget(); 311 views::Widget* widget = GetWidget();
294 views::FocusManager* focus_manager = GetFocusManager(); 312 views::FocusManager* focus_manager = GetFocusManager();
295 #if defined(OS_WIN) 313 #if defined(OS_WIN)
296 // If we gain focus, we want to restore it to the previously-focused element 314 // 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 315 // 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. 316 // that if we gain focus we'll know what the previously-focused element was.
299 if (widget) { 317 if (widget) {
300 focus_tracker_.reset( 318 focus_tracker_.reset(
301 new views::ExternalFocusTracker(this, focus_manager)); 319 new views::ExternalFocusTracker(this, focus_manager));
302 } 320 }
303 #endif 321 #endif
304 if (focus_manager) 322 if (focus_manager)
305 focus_manager->AddFocusChangeListener(this); 323 focus_manager->AddFocusChangeListener(this);
306 if (widget) { 324 if (widget) {
307 widget->NotifyAccessibilityEvent( 325 widget->NotifyAccessibilityEvent(
308 this, ui::AccessibilityTypes::EVENT_ALERT, true); 326 this, ui::AccessibilityTypes::EVENT_ALERT, true);
309 } 327 }
310 } 328 }
311 329
312 void InfoBarView::PlatformSpecificHide(bool animate) { 330 void InfoBarView::PlatformSpecificHide(bool animate) {
331 // We're being removed. Cancel any menus we may have open. Because we are
332 // deleted after a delay and after our delegate is deleted we have to
333 // explicitly cancel the menu rather than relying on the destructor to cancel
334 // the menu.
335 menu_runner_.reset();
336
313 // It's possible to be called twice (once with |animate| true and once with it 337 // 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 338 // false); in this case the second RemoveFocusChangeListener() call will
315 // silently no-op. 339 // silently no-op.
316 views::FocusManager* focus_manager = GetFocusManager(); 340 views::FocusManager* focus_manager = GetFocusManager();
317 if (focus_manager) 341 if (focus_manager)
318 focus_manager->RemoveFocusChangeListener(this); 342 focus_manager->RemoveFocusChangeListener(this);
319 343
320 #if defined(OS_WIN) && !defined(USE_AURA) 344 #if defined(OS_WIN) && !defined(USE_AURA)
321 if (!animate || !focus_tracker_.get()) 345 if (!animate || !focus_tracker_.get())
322 return; 346 return;
(...skipping 28 matching lines...) Expand all
351 375
352 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { 376 void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) {
353 // This will trigger some screen readers to read the entire contents of this 377 // This will trigger some screen readers to read the entire contents of this
354 // infobar. 378 // infobar.
355 if (focused_before && focused_now && !Contains(focused_before) && 379 if (focused_before && focused_now && !Contains(focused_before) &&
356 Contains(focused_now) && GetWidget()) { 380 Contains(focused_now) && GetWidget()) {
357 GetWidget()->NotifyAccessibilityEvent( 381 GetWidget()->NotifyAccessibilityEvent(
358 this, ui::AccessibilityTypes::EVENT_ALERT, true); 382 this, ui::AccessibilityTypes::EVENT_ALERT, true);
359 } 383 }
360 } 384 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/infobar_view.h ('k') | chrome/browser/ui/views/infobars/link_infobar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698