OLD | NEW |
---|---|
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" | 15 #include "chrome/browser/infobars/infobar_delegate.h" |
16 #include "chrome/browser/ui/views/infobars/infobar_background.h" | 16 #include "chrome/browser/ui/views/infobars/infobar_background.h" |
17 #include "chrome/browser/ui/views/infobars/infobar_button_border.h" | |
18 #include "chrome/browser/ui/views/infobars/infobar_label_button_border.h" | |
19 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
20 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
21 #include "grit/ui_resources.h" | 19 #include "grit/ui_resources.h" |
22 #include "third_party/skia/include/effects/SkGradientShader.h" | 20 #include "third_party/skia/include/effects/SkGradientShader.h" |
23 #include "ui/base/accessibility/accessible_view_state.h" | 21 #include "ui/base/accessibility/accessible_view_state.h" |
24 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
28 #include "ui/views/controls/button/image_button.h" | 26 #include "ui/views/controls/button/image_button.h" |
29 #include "ui/views/controls/button/label_button.h" | 27 #include "ui/views/controls/button/label_button.h" |
28 #include "ui/views/controls/button/label_button_border.h" | |
30 #include "ui/views/controls/button/menu_button.h" | 29 #include "ui/views/controls/button/menu_button.h" |
31 #include "ui/views/controls/image_view.h" | 30 #include "ui/views/controls/image_view.h" |
32 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
33 #include "ui/views/controls/link.h" | 32 #include "ui/views/controls/link.h" |
34 #include "ui/views/controls/menu/menu_runner.h" | 33 #include "ui/views/controls/menu/menu_runner.h" |
35 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
36 #include "ui/views/window/non_client_view.h" | 35 #include "ui/views/window/non_client_view.h" |
37 | 36 |
38 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
39 #include "base/win/win_util.h" | 38 #include "base/win/win_util.h" |
40 #include "base/win/windows_version.h" | 39 #include "base/win/windows_version.h" |
41 #include "ui/gfx/icon_util.h" | 40 #include "ui/gfx/icon_util.h" |
42 #include "ui/gfx/win/hwnd_util.h" | 41 #include "ui/gfx/win/hwnd_util.h" |
43 #endif | 42 #endif |
44 | 43 |
44 namespace { | |
45 | |
46 const int kInfoBarBorderPaddingVertical = 5; | |
47 | |
48 }; // namespace | |
sky
2013/11/22 14:42:44
nit: no ;
| |
49 | |
45 // static | 50 // static |
46 const int InfoBar::kSeparatorLineHeight = | 51 const int InfoBar::kSeparatorLineHeight = |
47 views::NonClientFrameView::kClientEdgeThickness; | 52 views::NonClientFrameView::kClientEdgeThickness; |
48 const int InfoBar::kDefaultArrowTargetHeight = 9; | 53 const int InfoBar::kDefaultArrowTargetHeight = 9; |
49 const int InfoBar::kMaximumArrowTargetHeight = 24; | 54 const int InfoBar::kMaximumArrowTargetHeight = 24; |
50 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; | 55 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; |
51 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; | 56 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; |
52 const int InfoBar::kDefaultBarTargetHeight = 36; | 57 const int InfoBar::kDefaultBarTargetHeight = 36; |
53 | 58 |
54 const int InfoBarView::kButtonButtonSpacing = 10; | 59 const int InfoBarView::kButtonButtonSpacing = 10; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 link->set_listener(listener); | 96 link->set_listener(listener); |
92 link->SetBackgroundColor(background()->get_color()); | 97 link->SetBackgroundColor(background()->get_color()); |
93 link->set_focusable(true); | 98 link->set_focusable(true); |
94 return link; | 99 return link; |
95 } | 100 } |
96 | 101 |
97 // static | 102 // static |
98 views::MenuButton* InfoBarView::CreateMenuButton( | 103 views::MenuButton* InfoBarView::CreateMenuButton( |
99 const string16& text, | 104 const string16& text, |
100 views::MenuButtonListener* menu_button_listener) { | 105 views::MenuButtonListener* menu_button_listener) { |
106 scoped_ptr<views::TextButtonDefaultBorder> menu_button_border( | |
107 new views::TextButtonDefaultBorder()); | |
108 menu_button_border->SetInsets(gfx::Insets(kInfoBarBorderPaddingVertical, 0, | |
109 kInfoBarBorderPaddingVertical, 0)); | |
110 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); | |
111 menu_button_border->set_normal_painter( | |
112 views::Painter::CreateImageGridPainter(kNormalImageSet)); | |
113 const int kHotImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); | |
114 menu_button_border->set_hot_painter( | |
115 views::Painter::CreateImageGridPainter(kHotImageSet)); | |
116 const int kPushedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); | |
117 menu_button_border->set_pushed_painter( | |
118 views::Painter::CreateImageGridPainter(kPushedImageSet)); | |
119 | |
101 views::MenuButton* menu_button = new views::MenuButton( | 120 views::MenuButton* menu_button = new views::MenuButton( |
102 NULL, text, menu_button_listener, true); | 121 NULL, text, menu_button_listener, true); |
103 menu_button->set_border(new InfoBarButtonBorder); | 122 menu_button->set_border(menu_button_border.release()); |
104 menu_button->set_animate_on_state_change(false); | 123 menu_button->set_animate_on_state_change(false); |
105 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 124 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
106 menu_button->set_menu_marker( | 125 menu_button->set_menu_marker( |
107 rb.GetImageNamed(IDR_INFOBARBUTTON_MENU_DROPARROW).ToImageSkia()); | 126 rb.GetImageNamed(IDR_INFOBARBUTTON_MENU_DROPARROW).ToImageSkia()); |
108 menu_button->SetEnabledColor(SK_ColorBLACK); | 127 menu_button->SetEnabledColor(SK_ColorBLACK); |
109 menu_button->SetHoverColor(SK_ColorBLACK); | 128 menu_button->SetHoverColor(SK_ColorBLACK); |
110 menu_button->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 129 menu_button->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
111 menu_button->set_focusable(true); | 130 menu_button->set_focusable(true); |
112 return menu_button; | 131 return menu_button; |
113 } | 132 } |
114 | 133 |
115 // static | 134 // static |
116 views::LabelButton* InfoBarView::CreateLabelButton( | 135 views::LabelButton* InfoBarView::CreateLabelButton( |
117 views::ButtonListener* listener, | 136 views::ButtonListener* listener, |
118 const string16& text, | 137 const string16& text, |
119 bool needs_elevation) { | 138 bool needs_elevation) { |
139 scoped_ptr<views::LabelButtonBorder> label_button_border( | |
140 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); | |
141 label_button_border->set_insets(gfx::Insets( | |
142 kInfoBarBorderPaddingVertical, 0, | |
143 kInfoBarBorderPaddingVertical, 0)); | |
144 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); | |
145 label_button_border->SetPainter( | |
146 false, views::Button::STATE_NORMAL, | |
147 views::Painter::CreateImageGridPainter(kNormalImageSet)); | |
148 const int kHoveredImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); | |
149 label_button_border->SetPainter( | |
150 false, views::Button::STATE_HOVERED, | |
151 views::Painter::CreateImageGridPainter(kHoveredImageSet)); | |
152 const int kPressedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); | |
153 label_button_border->SetPainter( | |
154 false, views::Button::STATE_PRESSED, | |
155 views::Painter::CreateImageGridPainter(kPressedImageSet)); | |
156 | |
120 views::LabelButton* label_button = new views::LabelButton(listener, text); | 157 views::LabelButton* label_button = new views::LabelButton(listener, text); |
121 label_button->set_border(new InfoBarLabelButtonBorder); | 158 label_button->set_border(label_button_border.release()); |
122 label_button->set_animate_on_state_change(false); | 159 label_button->set_animate_on_state_change(false); |
123 label_button->SetTextColor(views::Button::STATE_NORMAL, SK_ColorBLACK); | 160 label_button->SetTextColor(views::Button::STATE_NORMAL, SK_ColorBLACK); |
124 label_button->SetTextColor(views::Button::STATE_HOVERED, SK_ColorBLACK); | 161 label_button->SetTextColor(views::Button::STATE_HOVERED, SK_ColorBLACK); |
125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 162 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
126 label_button->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 163 label_button->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
127 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
128 if (needs_elevation && | 165 if (needs_elevation && |
129 (base::win::GetVersion() >= base::win::VERSION_VISTA) && | 166 (base::win::GetVersion() >= base::win::VERSION_VISTA) && |
130 base::win::UserAccountControlIsEnabled()) { | 167 base::win::UserAccountControlIsEnabled()) { |
131 SHSTOCKICONINFO icon_info = { sizeof(SHSTOCKICONINFO) }; | 168 SHSTOCKICONINFO icon_info = { sizeof(SHSTOCKICONINFO) }; |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { | 402 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { |
366 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); | 403 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); |
367 | 404 |
368 // This will trigger some screen readers to read the entire contents of this | 405 // This will trigger some screen readers to read the entire contents of this |
369 // infobar. | 406 // infobar. |
370 if (focused_before && focused_now && !Contains(focused_before) && | 407 if (focused_before && focused_now && !Contains(focused_before) && |
371 Contains(focused_now)) { | 408 Contains(focused_now)) { |
372 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); | 409 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); |
373 } | 410 } |
374 } | 411 } |
OLD | NEW |