| 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/infobars/infobar_background.h" | 14 #include "chrome/browser/ui/views/infobars/infobar_background.h" |
| 15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "chrome/grit/theme_resources.h" | 16 #include "chrome/grit/theme_resources.h" |
| 17 #include "components/infobars/core/infobar_delegate.h" | 17 #include "components/infobars/core/infobar_delegate.h" |
| 18 #include "components/strings/grit/components_strings.h" | 18 #include "components/strings/grit/components_strings.h" |
| 19 #include "third_party/skia/include/effects/SkGradientShader.h" | 19 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 20 #include "ui/accessibility/ax_node_data.h" | 20 #include "ui/accessibility/ax_node_data.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/color_palette.h" | 23 #include "ui/gfx/color_palette.h" |
| 24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
| 25 #include "ui/gfx/paint_vector_icon.h" | 25 #include "ui/gfx/paint_vector_icon.h" |
| 26 #include "ui/native_theme/common_theme.h" | 26 #include "ui/native_theme/common_theme.h" |
| 27 #include "ui/native_theme/native_theme.h" | 27 #include "ui/native_theme/native_theme.h" |
| 28 #include "ui/vector_icons/vector_icons.h" | 28 #include "ui/vector_icons/vector_icons.h" |
| 29 #include "ui/views/controls/button/image_button.h" | 29 #include "ui/views/controls/button/image_button.h" |
| 30 #include "ui/views/controls/button/image_button_factory.h" |
| 30 #include "ui/views/controls/button/label_button_border.h" | 31 #include "ui/views/controls/button/label_button_border.h" |
| 31 #include "ui/views/controls/button/md_text_button.h" | 32 #include "ui/views/controls/button/md_text_button.h" |
| 32 #include "ui/views/controls/button/menu_button.h" | 33 #include "ui/views/controls/button/menu_button.h" |
| 33 #include "ui/views/controls/button/vector_icon_button.h" | |
| 34 #include "ui/views/controls/image_view.h" | 34 #include "ui/views/controls/image_view.h" |
| 35 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
| 36 #include "ui/views/controls/link.h" | 36 #include "ui/views/controls/link.h" |
| 37 #include "ui/views/controls/menu/menu_runner.h" | 37 #include "ui/views/controls/menu/menu_runner.h" |
| 38 #include "ui/views/layout/layout_constants.h" | 38 #include "ui/views/layout/layout_constants.h" |
| 39 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
| 40 #include "ui/views/window/non_client_view.h" | 40 #include "ui/views/window/non_client_view.h" |
| 41 | 41 |
| 42 | 42 |
| 43 // Helpers -------------------------------------------------------------------- | 43 // Helpers -------------------------------------------------------------------- |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 if (details.is_add && (details.child == this) && (close_button_ == NULL)) { | 159 if (details.is_add && (details.child == this) && (close_button_ == NULL)) { |
| 160 gfx::Image image = delegate()->GetIcon(); | 160 gfx::Image image = delegate()->GetIcon(); |
| 161 if (!image.IsEmpty()) { | 161 if (!image.IsEmpty()) { |
| 162 icon_ = new views::ImageView; | 162 icon_ = new views::ImageView; |
| 163 icon_->SetImage(image.ToImageSkia()); | 163 icon_->SetImage(image.ToImageSkia()); |
| 164 icon_->SizeToPreferredSize(); | 164 icon_->SizeToPreferredSize(); |
| 165 child_container_->AddChildView(icon_); | 165 child_container_->AddChildView(icon_); |
| 166 } | 166 } |
| 167 | 167 |
| 168 close_button_ = new views::VectorIconButton(this); | 168 close_button_ = views::CreateVectorImageButton(this); |
| 169 close_button_->SetIcon(ui::kCloseIcon); | 169 views::SetImageFromVectorIcon(close_button_, ui::kCloseIcon, |
| 170 GetInfobarTextColor()); |
| 170 close_button_->SetAccessibleName( | 171 close_button_->SetAccessibleName( |
| 171 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 172 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 172 close_button_->SetFocusForPlatform(); | 173 close_button_->SetFocusForPlatform(); |
| 173 // Subclasses should already be done adding child views by this point (see | 174 // Subclasses should already be done adding child views by this point (see |
| 174 // related DCHECK in Layout()). | 175 // related DCHECK in Layout()). |
| 175 child_container_->AddChildView(close_button_); | 176 child_container_->AddChildView(close_button_); |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Ensure the infobar is tall enough to display its contents. | 179 // Ensure the infobar is tall enough to display its contents. |
| 179 int height = InfoBarContainerDelegate::kDefaultBarTargetHeight; | 180 int height = InfoBarContainerDelegate::kDefaultBarTargetHeight; |
| 180 const int kMinimumVerticalPadding = 6; | 181 const int kMinimumVerticalPadding = 6; |
| 181 for (int i = 0; i < child_container_->child_count(); ++i) { | 182 for (int i = 0; i < child_container_->child_count(); ++i) { |
| 182 const int child_height = child_container_->child_at(i)->height(); | 183 const int child_height = child_container_->child_at(i)->height(); |
| 183 height = std::max(height, child_height + kMinimumVerticalPadding); | 184 height = std::max(height, child_height + kMinimumVerticalPadding); |
| 184 } | 185 } |
| 185 SetBarTargetHeight(height); | 186 SetBarTargetHeight(height); |
| 186 } | 187 } |
| 187 | 188 |
| 188 void InfoBarView::ButtonPressed(views::Button* sender, | 189 void InfoBarView::ButtonPressed(views::Button* sender, |
| 189 const ui::Event& event) { | 190 const ui::Event& event) { |
| 190 if (!owner()) | 191 if (!owner()) |
| 191 return; // We're closing; don't call anything, it might access the owner. | 192 return; // We're closing; don't call anything, it might access the owner. |
| 192 if (sender == close_button_) { | 193 if (sender == close_button_) { |
| 193 delegate()->InfoBarDismissed(); | 194 delegate()->InfoBarDismissed(); |
| 194 RemoveSelf(); | 195 RemoveSelf(); |
| 195 } | 196 } |
| 196 } | 197 } |
| 197 | 198 |
| 198 SkColor InfoBarView::GetVectorIconBaseColor() const { | |
| 199 return GetInfobarTextColor(); | |
| 200 } | |
| 201 | |
| 202 int InfoBarView::ContentMinimumWidth() const { | 199 int InfoBarView::ContentMinimumWidth() const { |
| 203 return 0; | 200 return 0; |
| 204 } | 201 } |
| 205 | 202 |
| 206 int InfoBarView::StartX() const { | 203 int InfoBarView::StartX() const { |
| 207 // Ensure we don't return a value greater than EndX(), so children can safely | 204 // Ensure we don't return a value greater than EndX(), so children can safely |
| 208 // set something's width to "EndX() - StartX()" without risking that being | 205 // set something's width to "EndX() - StartX()" without risking that being |
| 209 // negative. | 206 // negative. |
| 210 return std::min(EndX(), (icon_ != NULL) ? | 207 return std::min(EndX(), (icon_ != NULL) ? |
| 211 (icon_->bounds().right() + kIconToLabelSpacing) : kEdgeItemPadding); | 208 (icon_->bounds().right() + kIconToLabelSpacing) : kEdgeItemPadding); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 } | 299 } |
| 303 | 300 |
| 304 bool InfoBarView::DoesIntersectRect(const View* target, | 301 bool InfoBarView::DoesIntersectRect(const View* target, |
| 305 const gfx::Rect& rect) const { | 302 const gfx::Rect& rect) const { |
| 306 DCHECK_EQ(this, target); | 303 DCHECK_EQ(this, target); |
| 307 // Only events that intersect the portion below the arrow are interesting. | 304 // Only events that intersect the portion below the arrow are interesting. |
| 308 gfx::Rect non_arrow_bounds = GetLocalBounds(); | 305 gfx::Rect non_arrow_bounds = GetLocalBounds(); |
| 309 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); | 306 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); |
| 310 return rect.Intersects(non_arrow_bounds); | 307 return rect.Intersects(non_arrow_bounds); |
| 311 } | 308 } |
| OLD | NEW |