| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 views::Link* InfoBarView::CreateLink(const string16& text, | 83 views::Link* InfoBarView::CreateLink(const string16& text, |
| 84 views::LinkListener* listener) const { | 84 views::LinkListener* listener) const { |
| 85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 86 views::Link* link = new views::Link; | 86 views::Link* link = new views::Link; |
| 87 link->SetText(text); | 87 link->SetText(text); |
| 88 link->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 88 link->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 89 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 89 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 90 link->set_listener(listener); | 90 link->set_listener(listener); |
| 91 link->SetBackgroundColor(background()->get_color()); | 91 link->SetBackgroundColor(background()->get_color()); |
| 92 link->set_focusable(true); | 92 link->SetFocusable(true); |
| 93 return link; | 93 return link; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // static | 96 // static |
| 97 views::MenuButton* InfoBarView::CreateMenuButton( | 97 views::MenuButton* InfoBarView::CreateMenuButton( |
| 98 const string16& text, | 98 const string16& text, |
| 99 views::MenuButtonListener* menu_button_listener) { | 99 views::MenuButtonListener* menu_button_listener) { |
| 100 scoped_ptr<views::TextButtonDefaultBorder> menu_button_border( | 100 scoped_ptr<views::TextButtonDefaultBorder> menu_button_border( |
| 101 new views::TextButtonDefaultBorder()); | 101 new views::TextButtonDefaultBorder()); |
| 102 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); | 102 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); |
| 103 menu_button_border->set_normal_painter( | 103 menu_button_border->set_normal_painter( |
| 104 views::Painter::CreateImageGridPainter(kNormalImageSet)); | 104 views::Painter::CreateImageGridPainter(kNormalImageSet)); |
| 105 const int kHotImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); | 105 const int kHotImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); |
| 106 menu_button_border->set_hot_painter( | 106 menu_button_border->set_hot_painter( |
| 107 views::Painter::CreateImageGridPainter(kHotImageSet)); | 107 views::Painter::CreateImageGridPainter(kHotImageSet)); |
| 108 const int kPushedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); | 108 const int kPushedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); |
| 109 menu_button_border->set_pushed_painter( | 109 menu_button_border->set_pushed_painter( |
| 110 views::Painter::CreateImageGridPainter(kPushedImageSet)); | 110 views::Painter::CreateImageGridPainter(kPushedImageSet)); |
| 111 | 111 |
| 112 views::MenuButton* menu_button = new views::MenuButton( | 112 views::MenuButton* menu_button = new views::MenuButton( |
| 113 NULL, text, menu_button_listener, true); | 113 NULL, text, menu_button_listener, true); |
| 114 menu_button->set_border(menu_button_border.release()); | 114 menu_button->set_border(menu_button_border.release()); |
| 115 menu_button->set_animate_on_state_change(false); | 115 menu_button->set_animate_on_state_change(false); |
| 116 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 116 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 117 menu_button->set_menu_marker( | 117 menu_button->set_menu_marker( |
| 118 rb.GetImageNamed(IDR_INFOBARBUTTON_MENU_DROPARROW).ToImageSkia()); | 118 rb.GetImageNamed(IDR_INFOBARBUTTON_MENU_DROPARROW).ToImageSkia()); |
| 119 menu_button->SetEnabledColor(SK_ColorBLACK); | 119 menu_button->SetEnabledColor(SK_ColorBLACK); |
| 120 menu_button->SetHoverColor(SK_ColorBLACK); | 120 menu_button->SetHoverColor(SK_ColorBLACK); |
| 121 menu_button->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 121 menu_button->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 122 menu_button->set_focusable(true); | 122 menu_button->SetFocusable(true); |
| 123 return menu_button; | 123 return menu_button; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // static | 126 // static |
| 127 views::LabelButton* InfoBarView::CreateLabelButton( | 127 views::LabelButton* InfoBarView::CreateLabelButton( |
| 128 views::ButtonListener* listener, | 128 views::ButtonListener* listener, |
| 129 const string16& text, | 129 const string16& text, |
| 130 bool needs_elevation) { | 130 bool needs_elevation) { |
| 131 scoped_ptr<views::LabelButtonBorder> label_button_border( | 131 scoped_ptr<views::LabelButtonBorder> label_button_border( |
| 132 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); | 132 new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 icon_info.hIcon, gfx::Size(GetSystemMetrics(SM_CXSMICON), | 168 icon_info.hIcon, gfx::Size(GetSystemMetrics(SM_CXSMICON), |
| 169 GetSystemMetrics(SM_CYSMICON)))); | 169 GetSystemMetrics(SM_CYSMICON)))); |
| 170 if (icon.get()) { | 170 if (icon.get()) { |
| 171 label_button->SetImage(views::Button::STATE_NORMAL, | 171 label_button->SetImage(views::Button::STATE_NORMAL, |
| 172 gfx::ImageSkia::CreateFrom1xBitmap(*icon)); | 172 gfx::ImageSkia::CreateFrom1xBitmap(*icon)); |
| 173 } | 173 } |
| 174 DestroyIcon(icon_info.hIcon); | 174 DestroyIcon(icon_info.hIcon); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 #endif | 177 #endif |
| 178 label_button->set_focusable(true); | 178 label_button->SetFocusable(true); |
| 179 return label_button; | 179 return label_button; |
| 180 } | 180 } |
| 181 | 181 |
| 182 void InfoBarView::Layout() { | 182 void InfoBarView::Layout() { |
| 183 // Calculate the fill and stroke paths. We do this here, rather than in | 183 // Calculate the fill and stroke paths. We do this here, rather than in |
| 184 // PlatformSpecificRecalculateHeight(), because this is also reached when our | 184 // PlatformSpecificRecalculateHeight(), because this is also reached when our |
| 185 // width is changed, which affects both paths. | 185 // width is changed, which affects both paths. |
| 186 stroke_path_.rewind(); | 186 stroke_path_.rewind(); |
| 187 fill_path_.rewind(); | 187 fill_path_.rewind(); |
| 188 const InfoBarContainer::Delegate* delegate = container_delegate(); | 188 const InfoBarContainer::Delegate* delegate = container_delegate(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 close_button_ = new views::ImageButton(this); | 252 close_button_ = new views::ImageButton(this); |
| 253 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 253 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 254 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 254 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
| 255 rb.GetImageNamed(IDR_CLOSE_1).ToImageSkia()); | 255 rb.GetImageNamed(IDR_CLOSE_1).ToImageSkia()); |
| 256 close_button_->SetImage(views::CustomButton::STATE_HOVERED, | 256 close_button_->SetImage(views::CustomButton::STATE_HOVERED, |
| 257 rb.GetImageNamed(IDR_CLOSE_1_H).ToImageSkia()); | 257 rb.GetImageNamed(IDR_CLOSE_1_H).ToImageSkia()); |
| 258 close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 258 close_button_->SetImage(views::CustomButton::STATE_PRESSED, |
| 259 rb.GetImageNamed(IDR_CLOSE_1_P).ToImageSkia()); | 259 rb.GetImageNamed(IDR_CLOSE_1_P).ToImageSkia()); |
| 260 close_button_->SetAccessibleName( | 260 close_button_->SetAccessibleName( |
| 261 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 261 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 262 close_button_->set_focusable(true); | 262 close_button_->SetFocusable(true); |
| 263 AddChildView(close_button_); | 263 AddChildView(close_button_); |
| 264 } else if ((close_button_ != NULL) && (details.parent == this) && | 264 } else if ((close_button_ != NULL) && (details.parent == this) && |
| 265 (details.child != close_button_) && (close_button_->parent() == this) && | 265 (details.child != close_button_) && (close_button_->parent() == this) && |
| 266 (child_at(child_count() - 1) != close_button_)) { | 266 (child_at(child_count() - 1) != close_button_)) { |
| 267 // For accessibility, ensure the close button is the last child view. | 267 // For accessibility, ensure the close button is the last child view. |
| 268 RemoveChildView(close_button_); | 268 RemoveChildView(close_button_); |
| 269 AddChildView(close_button_); | 269 AddChildView(close_button_); |
| 270 } | 270 } |
| 271 | 271 |
| 272 // Ensure the infobar is tall enough to display its contents. | 272 // Ensure the infobar is tall enough to display its contents. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { | 389 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { |
| 390 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); | 390 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); |
| 391 | 391 |
| 392 // This will trigger some screen readers to read the entire contents of this | 392 // This will trigger some screen readers to read the entire contents of this |
| 393 // infobar. | 393 // infobar. |
| 394 if (focused_before && focused_now && !Contains(focused_before) && | 394 if (focused_before && focused_now && !Contains(focused_before) && |
| 395 Contains(focused_now)) { | 395 Contains(focused_now)) { |
| 396 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); | 396 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_ALERT, true); |
| 397 } | 397 } |
| 398 } | 398 } |
| OLD | NEW |