| 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 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/ui/infobar_container_delegate.h" | 13 #include "chrome/browser/ui/infobar_container_delegate.h" |
| 14 #include "chrome/browser/ui/views/bar_control_button.h" | |
| 15 #include "chrome/browser/ui/views/infobars/infobar_background.h" | 14 #include "chrome/browser/ui/views/infobars/infobar_background.h" |
| 16 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 17 #include "chrome/grit/theme_resources.h" | 16 #include "chrome/grit/theme_resources.h" |
| 18 #include "components/infobars/core/infobar_delegate.h" | 17 #include "components/infobars/core/infobar_delegate.h" |
| 19 #include "components/strings/grit/components_strings.h" | 18 #include "components/strings/grit/components_strings.h" |
| 20 #include "third_party/skia/include/effects/SkGradientShader.h" | 19 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 21 #include "ui/accessibility/ax_view_state.h" | 20 #include "ui/accessibility/ax_view_state.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/material_design/material_design_controller.h" | 22 #include "ui/base/material_design/material_design_controller.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
| 26 #include "ui/gfx/color_palette.h" | 25 #include "ui/gfx/color_palette.h" |
| 27 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
| 28 #include "ui/gfx/paint_vector_icon.h" | 27 #include "ui/gfx/paint_vector_icon.h" |
| 29 #include "ui/gfx/vector_icons_public.h" | 28 #include "ui/gfx/vector_icons_public.h" |
| 30 #include "ui/native_theme/common_theme.h" | 29 #include "ui/native_theme/common_theme.h" |
| 31 #include "ui/native_theme/native_theme.h" | 30 #include "ui/native_theme/native_theme.h" |
| 32 #include "ui/resources/grit/ui_resources.h" | 31 #include "ui/resources/grit/ui_resources.h" |
| 33 #include "ui/views/controls/button/image_button.h" | 32 #include "ui/views/controls/button/image_button.h" |
| 34 #include "ui/views/controls/button/label_button.h" | 33 #include "ui/views/controls/button/label_button.h" |
| 35 #include "ui/views/controls/button/label_button_border.h" | 34 #include "ui/views/controls/button/label_button_border.h" |
| 36 #include "ui/views/controls/button/md_text_button.h" | 35 #include "ui/views/controls/button/md_text_button.h" |
| 37 #include "ui/views/controls/button/menu_button.h" | 36 #include "ui/views/controls/button/menu_button.h" |
| 37 #include "ui/views/controls/button/vector_icon_button.h" |
| 38 #include "ui/views/controls/image_view.h" | 38 #include "ui/views/controls/image_view.h" |
| 39 #include "ui/views/controls/label.h" | 39 #include "ui/views/controls/label.h" |
| 40 #include "ui/views/controls/link.h" | 40 #include "ui/views/controls/link.h" |
| 41 #include "ui/views/controls/menu/menu_runner.h" | 41 #include "ui/views/controls/menu/menu_runner.h" |
| 42 #include "ui/views/layout/layout_constants.h" | 42 #include "ui/views/layout/layout_constants.h" |
| 43 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
| 44 #include "ui/views/window/non_client_view.h" | 44 #include "ui/views/window/non_client_view.h" |
| 45 | 45 |
| 46 | 46 |
| 47 // Helpers -------------------------------------------------------------------- | 47 // Helpers -------------------------------------------------------------------- |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 if (details.is_add && (details.child == this) && (close_button_ == NULL)) { | 256 if (details.is_add && (details.child == this) && (close_button_ == NULL)) { |
| 257 gfx::Image image = delegate()->GetIcon(); | 257 gfx::Image image = delegate()->GetIcon(); |
| 258 if (!image.IsEmpty()) { | 258 if (!image.IsEmpty()) { |
| 259 icon_ = new views::ImageView; | 259 icon_ = new views::ImageView; |
| 260 icon_->SetImage(image.ToImageSkia()); | 260 icon_->SetImage(image.ToImageSkia()); |
| 261 icon_->SizeToPreferredSize(); | 261 icon_->SizeToPreferredSize(); |
| 262 child_container_->AddChildView(icon_); | 262 child_container_->AddChildView(icon_); |
| 263 } | 263 } |
| 264 | 264 |
| 265 if (ui::MaterialDesignController::IsModeMaterial()) { | 265 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 266 BarControlButton* close = new BarControlButton(this); | 266 views::VectorIconButton* close = new views::VectorIconButton(this); |
| 267 close->SetIcon(gfx::VectorIconId::BAR_CLOSE, | 267 close->SetIcon(gfx::VectorIconId::BAR_CLOSE); |
| 268 base::Bind(&GetInfobarTextColor)); | |
| 269 close_button_ = close; | 268 close_button_ = close; |
| 270 } else { | 269 } else { |
| 271 close_button_ = new views::ImageButton(this); | 270 close_button_ = new views::ImageButton(this); |
| 272 close_button_->set_request_focus_on_press(true); | 271 close_button_->set_request_focus_on_press(true); |
| 273 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 272 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 274 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 273 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
| 275 rb.GetImageNamed(IDR_CLOSE_1).ToImageSkia()); | 274 rb.GetImageNamed(IDR_CLOSE_1).ToImageSkia()); |
| 276 close_button_->SetImage(views::CustomButton::STATE_HOVERED, | 275 close_button_->SetImage(views::CustomButton::STATE_HOVERED, |
| 277 rb.GetImageNamed(IDR_CLOSE_1_H).ToImageSkia()); | 276 rb.GetImageNamed(IDR_CLOSE_1_H).ToImageSkia()); |
| 278 close_button_->SetImage(views::CustomButton::STATE_PRESSED, | 277 close_button_->SetImage(views::CustomButton::STATE_PRESSED, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 301 void InfoBarView::ButtonPressed(views::Button* sender, | 300 void InfoBarView::ButtonPressed(views::Button* sender, |
| 302 const ui::Event& event) { | 301 const ui::Event& event) { |
| 303 if (!owner()) | 302 if (!owner()) |
| 304 return; // We're closing; don't call anything, it might access the owner. | 303 return; // We're closing; don't call anything, it might access the owner. |
| 305 if (sender == close_button_) { | 304 if (sender == close_button_) { |
| 306 delegate()->InfoBarDismissed(); | 305 delegate()->InfoBarDismissed(); |
| 307 RemoveSelf(); | 306 RemoveSelf(); |
| 308 } | 307 } |
| 309 } | 308 } |
| 310 | 309 |
| 310 SkColor InfoBarView::GetVectorIconBaseColor() const { |
| 311 return GetInfobarTextColor(); |
| 312 } |
| 313 |
| 311 int InfoBarView::ContentMinimumWidth() const { | 314 int InfoBarView::ContentMinimumWidth() const { |
| 312 return 0; | 315 return 0; |
| 313 } | 316 } |
| 314 | 317 |
| 315 int InfoBarView::StartX() const { | 318 int InfoBarView::StartX() const { |
| 316 // Ensure we don't return a value greater than EndX(), so children can safely | 319 // Ensure we don't return a value greater than EndX(), so children can safely |
| 317 // set something's width to "EndX() - StartX()" without risking that being | 320 // set something's width to "EndX() - StartX()" without risking that being |
| 318 // negative. | 321 // negative. |
| 319 return std::min(EndX(), (icon_ != NULL) ? | 322 return std::min(EndX(), (icon_ != NULL) ? |
| 320 (icon_->bounds().right() + kIconToLabelSpacing) : kEdgeItemPadding); | 323 (icon_->bounds().right() + kIconToLabelSpacing) : kEdgeItemPadding); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 } | 430 } |
| 428 | 431 |
| 429 bool InfoBarView::DoesIntersectRect(const View* target, | 432 bool InfoBarView::DoesIntersectRect(const View* target, |
| 430 const gfx::Rect& rect) const { | 433 const gfx::Rect& rect) const { |
| 431 DCHECK_EQ(this, target); | 434 DCHECK_EQ(this, target); |
| 432 // Only events that intersect the portion below the arrow are interesting. | 435 // Only events that intersect the portion below the arrow are interesting. |
| 433 gfx::Rect non_arrow_bounds = GetLocalBounds(); | 436 gfx::Rect non_arrow_bounds = GetLocalBounds(); |
| 434 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); | 437 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); |
| 435 return rect.Intersects(non_arrow_bounds); | 438 return rect.Intersects(non_arrow_bounds); |
| 436 } | 439 } |
| OLD | NEW |