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

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

Issue 240193003: Move Infobars core files to the Infobars component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nib name on mac Created 6 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #endif 9 #endif
10 10
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/infobars/infobar_delegate.h"
16 #include "chrome/browser/ui/views/infobars/infobar_background.h" 15 #include "chrome/browser/ui/views/infobars/infobar_background.h"
16 #include "components/infobars/core/infobar_delegate.h"
17 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
19 #include "grit/ui_resources.h" 19 #include "grit/ui_resources.h"
20 #include "third_party/skia/include/effects/SkGradientShader.h" 20 #include "third_party/skia/include/effects/SkGradientShader.h"
21 #include "ui/accessibility/ax_view_state.h" 21 #include "ui/accessibility/ax_view_state.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
26 #include "ui/views/controls/button/image_button.h" 26 #include "ui/views/controls/button/image_button.h"
(...skipping 23 matching lines...) Expand all
50 return label_1->GetPreferredSize().width() > 50 return label_1->GetPreferredSize().width() >
51 label_2->GetPreferredSize().width(); 51 label_2->GetPreferredSize().width();
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 56
57 // InfoBar -------------------------------------------------------------------- 57 // InfoBar --------------------------------------------------------------------
58 58
59 // static 59 // static
60 const int InfoBar::kSeparatorLineHeight = 60 const int infobars::InfoBar::kSeparatorLineHeight =
61 views::NonClientFrameView::kClientEdgeThickness; 61 views::NonClientFrameView::kClientEdgeThickness;
62 const int InfoBar::kDefaultArrowTargetHeight = 9; 62 const int infobars::InfoBar::kDefaultArrowTargetHeight = 9;
63 const int InfoBar::kMaximumArrowTargetHeight = 24; 63 const int infobars::InfoBar::kMaximumArrowTargetHeight = 24;
64 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; 64 const int infobars::InfoBar::kDefaultArrowTargetHalfWidth =
65 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; 65 kDefaultArrowTargetHeight;
66 const int InfoBar::kDefaultBarTargetHeight = 36; 66 const int infobars::InfoBar::kMaximumArrowTargetHalfWidth = 14;
67 67 const int infobars::InfoBar::kDefaultBarTargetHeight = 36;
68 68
69 // InfoBarView ---------------------------------------------------------------- 69 // InfoBarView ----------------------------------------------------------------
70 70
71 // static 71 // static
72 const int InfoBarView::kButtonButtonSpacing = 10; 72 const int InfoBarView::kButtonButtonSpacing = 10;
73 const int InfoBarView::kEndOfLabelSpacing = 16; 73 const int InfoBarView::kEndOfLabelSpacing = 16;
74 const int InfoBarView::kHorizontalPadding = 6; 74 const int InfoBarView::kHorizontalPadding = 6;
75 const int InfoBarView::kCloseButtonSpacing = kEndOfLabelSpacing; 75 const int InfoBarView::kCloseButtonSpacing = kEndOfLabelSpacing;
76 76
77 InfoBarView::InfoBarView(scoped_ptr<InfoBarDelegate> delegate) 77 InfoBarView::InfoBarView(scoped_ptr<infobars::InfoBarDelegate> delegate)
78 : InfoBar(delegate.Pass()), 78 : infobars::InfoBar(delegate.Pass()),
79 views::ExternalFocusTracker(this, NULL), 79 views::ExternalFocusTracker(this, NULL),
80 icon_(NULL), 80 icon_(NULL),
81 close_button_(NULL) { 81 close_button_(NULL) {
82 set_owned_by_client(); // InfoBar deletes itself at the appropriate time. 82 set_owned_by_client(); // InfoBar deletes itself at the appropriate time.
83 set_background(new InfoBarBackground(InfoBar::delegate()->GetInfoBarType())); 83 set_background(
84 new InfoBarBackground(infobars::InfoBar::delegate()->GetInfoBarType()));
84 } 85 }
85 86
86 InfoBarView::~InfoBarView() { 87 InfoBarView::~InfoBarView() {
87 // We should have closed any open menus in PlatformSpecificHide(), then 88 // We should have closed any open menus in PlatformSpecificHide(), then
88 // subclasses' RunMenu() functions should have prevented opening any new ones 89 // subclasses' RunMenu() functions should have prevented opening any new ones
89 // once we became unowned. 90 // once we became unowned.
90 DCHECK(!menu_runner_.get()); 91 DCHECK(!menu_runner_.get());
91 } 92 }
92 93
93 views::Label* InfoBarView::CreateLabel(const base::string16& text) const { 94 views::Label* InfoBarView::CreateLabel(const base::string16& text) const {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); 207 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth);
207 AssignWidthsSorted(labels, available_width); 208 AssignWidthsSorted(labels, available_width);
208 } 209 }
209 210
210 void InfoBarView::Layout() { 211 void InfoBarView::Layout() {
211 // Calculate the fill and stroke paths. We do this here, rather than in 212 // Calculate the fill and stroke paths. We do this here, rather than in
212 // PlatformSpecificRecalculateHeight(), because this is also reached when our 213 // PlatformSpecificRecalculateHeight(), because this is also reached when our
213 // width is changed, which affects both paths. 214 // width is changed, which affects both paths.
214 stroke_path_.rewind(); 215 stroke_path_.rewind();
215 fill_path_.rewind(); 216 fill_path_.rewind();
216 const InfoBarContainer::Delegate* delegate = container_delegate(); 217 const infobars::InfoBarContainer::Delegate* delegate = container_delegate();
217 if (delegate) { 218 if (delegate) {
218 static_cast<InfoBarBackground*>(background())->set_separator_color( 219 static_cast<InfoBarBackground*>(background())->set_separator_color(
219 delegate->GetInfoBarSeparatorColor()); 220 delegate->GetInfoBarSeparatorColor());
220 int arrow_x; 221 int arrow_x;
221 SkScalar arrow_fill_height = 222 SkScalar arrow_fill_height =
222 SkIntToScalar(std::max(arrow_height() - kSeparatorLineHeight, 0)); 223 SkIntToScalar(std::max(arrow_height() - kSeparatorLineHeight, 0));
223 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width()); 224 SkScalar arrow_fill_half_width = SkIntToScalar(arrow_half_width());
224 SkScalar separator_height = SkIntToScalar(kSeparatorLineHeight); 225 SkScalar separator_height = SkIntToScalar(kSeparatorLineHeight);
225 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) { 226 if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) {
226 // Skia pixel centers are at the half-values, so the arrow is horizontally 227 // Skia pixel centers are at the half-values, so the arrow is horizontally
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 int InfoBarView::EndX() const { 351 int InfoBarView::EndX() const {
351 return close_button_->x() - kCloseButtonSpacing; 352 return close_button_->x() - kCloseButtonSpacing;
352 } 353 }
353 354
354 int InfoBarView::OffsetY(views::View* view) const { 355 int InfoBarView::OffsetY(views::View* view) const {
355 return arrow_height() + 356 return arrow_height() +
356 std::max((bar_target_height() - view->height()) / 2, 0) - 357 std::max((bar_target_height() - view->height()) / 2, 0) -
357 (bar_target_height() - bar_height()); 358 (bar_target_height() - bar_height());
358 } 359 }
359 360
360 const InfoBarContainer::Delegate* InfoBarView::container_delegate() const { 361 const infobars::InfoBarContainer::Delegate* InfoBarView::container_delegate()
361 const InfoBarContainer* infobar_container = container(); 362 const {
363 const infobars::InfoBarContainer* infobar_container = container();
362 return infobar_container ? infobar_container->delegate() : NULL; 364 return infobar_container ? infobar_container->delegate() : NULL;
363 } 365 }
364 366
365 void InfoBarView::RunMenuAt(ui::MenuModel* menu_model, 367 void InfoBarView::RunMenuAt(ui::MenuModel* menu_model,
366 views::MenuButton* button, 368 views::MenuButton* button,
367 views::MenuItemView::AnchorPosition anchor) { 369 views::MenuItemView::AnchorPosition anchor) {
368 DCHECK(owner()); // We'd better not open any menus while we're closing. 370 DCHECK(owner()); // We'd better not open any menus while we're closing.
369 gfx::Point screen_point; 371 gfx::Point screen_point;
370 views::View::ConvertPointToScreen(button, &screen_point); 372 views::View::ConvertPointToScreen(button, &screen_point);
371 menu_runner_.reset(new views::MenuRunner(menu_model)); 373 menu_runner_.reset(new views::MenuRunner(menu_model));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 } 421 }
420 422
421 void InfoBarView::PlatformSpecificOnHeightsRecalculated() { 423 void InfoBarView::PlatformSpecificOnHeightsRecalculated() {
422 // Ensure that notifying our container of our size change will result in a 424 // Ensure that notifying our container of our size change will result in a
423 // re-layout. 425 // re-layout.
424 InvalidateLayout(); 426 InvalidateLayout();
425 } 427 }
426 428
427 void InfoBarView::GetAccessibleState(ui::AXViewState* state) { 429 void InfoBarView::GetAccessibleState(ui::AXViewState* state) {
428 state->name = l10n_util::GetStringUTF16( 430 state->name = l10n_util::GetStringUTF16(
429 (delegate()->GetInfoBarType() == InfoBarDelegate::WARNING_TYPE) ? 431 (delegate()->GetInfoBarType() ==
432 infobars::InfoBarDelegate::WARNING_TYPE) ?
430 IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION); 433 IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION);
431 state->role = ui::AX_ROLE_ALERT; 434 state->role = ui::AX_ROLE_ALERT;
432 } 435 }
433 436
434 gfx::Size InfoBarView::GetPreferredSize() { 437 gfx::Size InfoBarView::GetPreferredSize() {
435 return gfx::Size( 438 return gfx::Size(
436 kHorizontalPadding + (icon_ ? (icon_->width() + kHorizontalPadding) : 0) + 439 kHorizontalPadding + (icon_ ? (icon_->width() + kHorizontalPadding) : 0) +
437 ContentMinimumWidth() + kCloseButtonSpacing + close_button_->width() + 440 ContentMinimumWidth() + kCloseButtonSpacing + close_button_->width() +
438 kHorizontalPadding, 441 kHorizontalPadding,
439 total_height()); 442 total_height());
440 } 443 }
441 444
442 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { 445 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) {
443 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); 446 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now);
444 447
445 // This will trigger some screen readers to read the entire contents of this 448 // This will trigger some screen readers to read the entire contents of this
446 // infobar. 449 // infobar.
447 if (focused_before && focused_now && !Contains(focused_before) && 450 if (focused_before && focused_now && !Contains(focused_before) &&
448 Contains(focused_now)) { 451 Contains(focused_now)) {
449 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 452 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
450 } 453 }
451 } 454 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/infobar_view.h ('k') | chrome/browser/ui/views/infobars/translate_infobar_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698