| 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 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 views::Link* InfoBarView::CreateLink(const base::string16& text, | 91 views::Link* InfoBarView::CreateLink(const base::string16& text, |
| 92 views::LinkListener* listener) const { | 92 views::LinkListener* listener) const { |
| 93 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 93 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 94 views::Link* link = new views::Link; | 94 views::Link* link = new views::Link; |
| 95 link->SetText(text); | 95 link->SetText(text); |
| 96 link->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 96 link->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 97 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 97 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 98 link->set_listener(listener); | 98 link->set_listener(listener); |
| 99 link->SetBackgroundColor(background()->get_color()); | 99 link->SetBackgroundColor(background()->get_color()); |
| 100 link->set_focusable(true); | 100 link->SetFocusable(true); |
| 101 return link; | 101 return link; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 views::MenuButton* InfoBarView::CreateMenuButton( | 105 views::MenuButton* InfoBarView::CreateMenuButton( |
| 106 const base::string16& text, | 106 const base::string16& text, |
| 107 views::MenuButtonListener* menu_button_listener) { | 107 views::MenuButtonListener* menu_button_listener) { |
| 108 scoped_ptr<views::TextButtonDefaultBorder> menu_button_border( | 108 scoped_ptr<views::TextButtonDefaultBorder> menu_button_border( |
| 109 new views::TextButtonDefaultBorder()); | 109 new views::TextButtonDefaultBorder()); |
| 110 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); | 110 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); |
| 111 menu_button_border->set_normal_painter( | 111 menu_button_border->set_normal_painter( |
| 112 views::Painter::CreateImageGridPainter(kNormalImageSet)); | 112 views::Painter::CreateImageGridPainter(kNormalImageSet)); |
| 113 const int kHotImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); | 113 const int kHotImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); |
| 114 menu_button_border->set_hot_painter( | 114 menu_button_border->set_hot_painter( |
| 115 views::Painter::CreateImageGridPainter(kHotImageSet)); | 115 views::Painter::CreateImageGridPainter(kHotImageSet)); |
| 116 const int kPushedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); | 116 const int kPushedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); |
| 117 menu_button_border->set_pushed_painter( | 117 menu_button_border->set_pushed_painter( |
| 118 views::Painter::CreateImageGridPainter(kPushedImageSet)); | 118 views::Painter::CreateImageGridPainter(kPushedImageSet)); |
| 119 | 119 |
| 120 views::MenuButton* menu_button = new views::MenuButton( | 120 views::MenuButton* menu_button = new views::MenuButton( |
| 121 NULL, text, menu_button_listener, true); | 121 NULL, text, menu_button_listener, true); |
| 122 menu_button->set_border(menu_button_border.release()); | 122 menu_button->set_border(menu_button_border.release()); |
| 123 menu_button->set_animate_on_state_change(false); | 123 menu_button->set_animate_on_state_change(false); |
| 124 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 124 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 125 menu_button->set_menu_marker( | 125 menu_button->set_menu_marker( |
| 126 rb.GetImageNamed(IDR_INFOBARBUTTON_MENU_DROPARROW).ToImageSkia()); | 126 rb.GetImageNamed(IDR_INFOBARBUTTON_MENU_DROPARROW).ToImageSkia()); |
| 127 menu_button->SetEnabledColor(SK_ColorBLACK); | 127 menu_button->SetEnabledColor(SK_ColorBLACK); |
| 128 menu_button->SetHoverColor(SK_ColorBLACK); | 128 menu_button->SetHoverColor(SK_ColorBLACK); |
| 129 menu_button->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 129 menu_button->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 130 menu_button->set_focusable(true); | 130 menu_button->SetFocusable(true); |
| 131 return menu_button; | 131 return menu_button; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // static | 134 // static |
| 135 views::LabelButton* InfoBarView::CreateLabelButton( | 135 views::LabelButton* InfoBarView::CreateLabelButton( |
| 136 views::ButtonListener* listener, | 136 views::ButtonListener* listener, |
| 137 const base::string16& text, | 137 const base::string16& text, |
| 138 bool needs_elevation) { | 138 bool needs_elevation) { |
| 139 scoped_ptr<views::LabelButtonBorder> label_button_border( | 139 scoped_ptr<views::LabelButtonBorder> label_button_border( |
| 140 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); | 140 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 icon_info.hIcon, gfx::Size(GetSystemMetrics(SM_CXSMICON), | 176 icon_info.hIcon, gfx::Size(GetSystemMetrics(SM_CXSMICON), |
| 177 GetSystemMetrics(SM_CYSMICON)))); | 177 GetSystemMetrics(SM_CYSMICON)))); |
| 178 if (icon.get()) { | 178 if (icon.get()) { |
| 179 label_button->SetImage(views::Button::STATE_NORMAL, | 179 label_button->SetImage(views::Button::STATE_NORMAL, |
| 180 gfx::ImageSkia::CreateFrom1xBitmap(*icon)); | 180 gfx::ImageSkia::CreateFrom1xBitmap(*icon)); |
| 181 } | 181 } |
| 182 DestroyIcon(icon_info.hIcon); | 182 DestroyIcon(icon_info.hIcon); |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 #endif | 185 #endif |
| 186 label_button->set_focusable(true); | 186 label_button->SetFocusable(true); |
| 187 return label_button; | 187 return label_button; |
| 188 } | 188 } |
| 189 | 189 |
| 190 void InfoBarView::Layout() { | 190 void InfoBarView::Layout() { |
| 191 // Calculate the fill and stroke paths. We do this here, rather than in | 191 // Calculate the fill and stroke paths. We do this here, rather than in |
| 192 // PlatformSpecificRecalculateHeight(), because this is also reached when our | 192 // PlatformSpecificRecalculateHeight(), because this is also reached when our |
| 193 // width is changed, which affects both paths. | 193 // width is changed, which affects both paths. |
| 194 stroke_path_.rewind(); | 194 stroke_path_.rewind(); |
| 195 fill_path_.rewind(); | 195 fill_path_.rewind(); |
| 196 const InfoBarContainer::Delegate* delegate = container_delegate(); | 196 const InfoBarContainer::Delegate* delegate = container_delegate(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 close_button_ = new views::ImageButton(this); | 264 close_button_ = new views::ImageButton(this); |
| 265 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 265 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 266 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 266 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
| 267 rb.GetImageNamed(IDR_CLOSE_1).ToImageSkia()); | 267 rb.GetImageNamed(IDR_CLOSE_1).ToImageSkia()); |
| 268 close_button_->SetImage(views::CustomButton::STATE_HOVERED, | 268 close_button_->SetImage(views::CustomButton::STATE_HOVERED, |
| 269 rb.GetImageNamed(IDR_CLOSE_1_H).ToImageSkia()); | 269 rb.GetImageNamed(IDR_CLOSE_1_H).ToImageSkia()); |
| 270 close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 270 close_button_->SetImage(views::CustomButton::STATE_PRESSED, |
| 271 rb.GetImageNamed(IDR_CLOSE_1_P).ToImageSkia()); | 271 rb.GetImageNamed(IDR_CLOSE_1_P).ToImageSkia()); |
| 272 close_button_->SetAccessibleName( | 272 close_button_->SetAccessibleName( |
| 273 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 273 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 274 close_button_->set_focusable(true); | 274 close_button_->SetFocusable(true); |
| 275 AddChildView(close_button_); | 275 AddChildView(close_button_); |
| 276 } else if ((close_button_ != NULL) && (details.parent == this) && | 276 } else if ((close_button_ != NULL) && (details.parent == this) && |
| 277 (details.child != close_button_) && (close_button_->parent() == this) && | 277 (details.child != close_button_) && (close_button_->parent() == this) && |
| 278 (child_at(child_count() - 1) != close_button_)) { | 278 (child_at(child_count() - 1) != close_button_)) { |
| 279 // For accessibility, ensure the close button is the last child view. | 279 // For accessibility, ensure the close button is the last child view. |
| 280 RemoveChildView(close_button_); | 280 RemoveChildView(close_button_); |
| 281 AddChildView(close_button_); | 281 AddChildView(close_button_); |
| 282 } | 282 } |
| 283 | 283 |
| 284 // Ensure the infobar is tall enough to display its contents. | 284 // Ensure the infobar is tall enough to display its contents. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { | 412 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { |
| 413 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); | 413 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); |
| 414 | 414 |
| 415 // This will trigger some screen readers to read the entire contents of this | 415 // This will trigger some screen readers to read the entire contents of this |
| 416 // infobar. | 416 // infobar. |
| 417 if (focused_before && focused_now && !Contains(focused_before) && | 417 if (focused_before && focused_now && !Contains(focused_before) && |
| 418 Contains(focused_now)) { | 418 Contains(focused_now)) { |
| 419 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); | 419 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); |
| 420 } | 420 } |
| 421 } | 421 } |
| OLD | NEW |