| 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 "ui/views/button_drag_utils.h" | 5 #include "ui/views/button_drag_utils.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "ui/base/dragdrop/drag_utils.h" | 8 #include "ui/base/dragdrop/drag_utils.h" |
| 9 #include "ui/base/dragdrop/os_exchange_data.h" | 9 #include "ui/base/dragdrop/os_exchange_data.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/compositor/canvas_painter.h" | 11 #include "ui/compositor/canvas_painter.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/geometry/point.h" | 13 #include "ui/gfx/geometry/point.h" |
| 14 #include "ui/gfx/geometry/vector2d.h" | 14 #include "ui/gfx/geometry/vector2d.h" |
| 15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 #include "ui/resources/grit/ui_resources.h" | 16 #include "ui/resources/grit/ui_resources.h" |
| 17 #include "ui/views/background.h" |
| 18 #include "ui/views/border.h" |
| 17 #include "ui/views/controls/button/label_button.h" | 19 #include "ui/views/controls/button/label_button.h" |
| 20 #include "ui/views/controls/button/label_button_border.h" |
| 18 #include "ui/views/drag_utils.h" | 21 #include "ui/views/drag_utils.h" |
| 19 #include "ui/views/resources/grit/views_resources.h" | 22 #include "ui/views/resources/grit/views_resources.h" |
| 20 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 21 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 22 | 25 |
| 23 namespace button_drag_utils { | 26 namespace button_drag_utils { |
| 24 | 27 |
| 25 // Maximum width of the link drag image in pixels. | 28 // Maximum width of the link drag image in pixels. |
| 26 static const int kLinkDragImageMaxWidth = 150; | 29 static const int kLinkDragImageMaxWidth = 150; |
| 27 | 30 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 42 const gfx::Point* press_pt, | 45 const gfx::Point* press_pt, |
| 43 ui::OSExchangeData* data, | 46 ui::OSExchangeData* data, |
| 44 views::Widget* widget) { | 47 views::Widget* widget) { |
| 45 // Create a button to render the drag image for us. | 48 // Create a button to render the drag image for us. |
| 46 views::LabelButton button(NULL, | 49 views::LabelButton button(NULL, |
| 47 title.empty() ? base::UTF8ToUTF16(url.spec()) | 50 title.empty() ? base::UTF8ToUTF16(url.spec()) |
| 48 : title); | 51 : title); |
| 49 button.SetTextSubpixelRenderingEnabled(false); | 52 button.SetTextSubpixelRenderingEnabled(false); |
| 50 const ui::NativeTheme* theme = widget->GetNativeTheme(); | 53 const ui::NativeTheme* theme = widget->GetNativeTheme(); |
| 51 button.SetTextColor(views::Button::STATE_NORMAL, | 54 button.SetTextColor(views::Button::STATE_NORMAL, |
| 52 theme->GetSystemColor(ui::NativeTheme::kColorId_LabelEnabledColor)); | 55 theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldDefaultColor)); |
| 53 gfx::ShadowValues shadows( | 56 |
| 54 10, | 57 SkColor bg_color = theme->GetSystemColor( |
| 55 gfx::ShadowValue(gfx::Vector2d(0, 0), 1.0f, | 58 ui::NativeTheme::kColorId_TextfieldDefaultBackground); |
| 56 theme->GetSystemColor( | 59 if (widget->IsTranslucentWindowOpacitySupported()) { |
| 57 ui::NativeTheme::kColorId_LabelBackgroundColor))); | 60 button.SetTextShadows(gfx::ShadowValues( |
| 58 button.SetTextShadows(shadows); | 61 10, gfx::ShadowValue(gfx::Vector2d(0, 0), 1.0f, bg_color))); |
| 62 } else { |
| 63 button.set_background(views::Background::CreateSolidBackground(bg_color)); |
| 64 button.SetBorder(button.CreateDefaultBorder()); |
| 65 } |
| 59 button.SetMaxSize(gfx::Size(kLinkDragImageMaxWidth, 0)); | 66 button.SetMaxSize(gfx::Size(kLinkDragImageMaxWidth, 0)); |
| 60 if (icon.isNull()) { | 67 if (icon.isNull()) { |
| 61 button.SetImage(views::Button::STATE_NORMAL, | 68 button.SetImage(views::Button::STATE_NORMAL, |
| 62 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 69 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 63 IDR_DEFAULT_FAVICON).ToImageSkia()); | 70 IDR_DEFAULT_FAVICON).ToImageSkia()); |
| 64 } else { | 71 } else { |
| 65 button.SetImage(views::Button::STATE_NORMAL, icon); | 72 button.SetImage(views::Button::STATE_NORMAL, icon); |
| 66 } | 73 } |
| 67 gfx::Size prefsize = button.GetPreferredSize(); | 74 gfx::Size prefsize = button.GetPreferredSize(); |
| 68 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); | 75 button.SetBounds(0, 0, prefsize.width(), prefsize.height()); |
| 69 | 76 |
| 70 gfx::Vector2d press_point; | 77 gfx::Vector2d press_point; |
| 71 if (press_pt) | 78 if (press_pt) |
| 72 press_point = press_pt->OffsetFromOrigin(); | 79 press_point = press_pt->OffsetFromOrigin(); |
| 73 else | 80 else |
| 74 press_point = gfx::Vector2d(prefsize.width() / 2, prefsize.height() / 2); | 81 press_point = gfx::Vector2d(prefsize.width() / 2, prefsize.height() / 2); |
| 75 | 82 |
| 76 // Render the image. | 83 // Render the image. |
| 77 scoped_ptr<gfx::Canvas> canvas( | 84 scoped_ptr<gfx::Canvas> canvas( |
| 78 views::GetCanvasForDragImage(widget, prefsize)); | 85 views::GetCanvasForDragImage(widget, prefsize)); |
| 79 button.Paint(ui::CanvasPainter(canvas.get(), 1.f).context()); | 86 button.Paint(ui::CanvasPainter(canvas.get(), 1.f).context()); |
| 80 drag_utils::SetDragImageOnDataObject(*canvas, press_point, data); | 87 drag_utils::SetDragImageOnDataObject(*canvas, press_point, data); |
| 81 } | 88 } |
| 82 | 89 |
| 83 } // namespace button_drag_utils | 90 } // namespace button_drag_utils |
| OLD | NEW |