| 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/dropdown_bar_view.h" | 5 #include "chrome/browser/ui/views/dropdown_bar_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/themes/theme_service.h" | 7 #include "chrome/browser/themes/theme_service.h" |
| 8 #include "chrome/browser/ui/view_ids.h" | 8 #include "chrome/browser/ui/view_ids.h" |
| 9 #include "chrome/browser/ui/views/frame/browser_view.h" | 9 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 11 #include "grit/theme_resources_standard.h" | 11 #include "grit/theme_resources_standard.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/core/SkRect.h" | 13 #include "third_party/skia/include/core/SkRect.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/image/image_skia.h" |
| 16 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
| 17 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
| 18 #include "ui/views/painter.h" | 19 #include "ui/views/painter.h" |
| 19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 // When we are animating, we draw only the top part of the left and right | 24 // When we are animating, we draw only the top part of the left and right |
| 24 // edges to give the illusion that the find dialog is attached to the | 25 // edges to give the illusion that the find dialog is attached to the |
| 25 // window during this animation; this is the height of the items we draw. | 26 // window during this animation; this is the height of the items we draw. |
| 26 const int kAnimatingEdgeHeight = 5; | 27 const int kAnimatingEdgeHeight = 5; |
| 27 | 28 |
| 28 // Background to paint toolbar background with rounded corners. | 29 // Background to paint toolbar background with rounded corners. |
| 29 class DropdownBackground : public views::Background { | 30 class DropdownBackground : public views::Background { |
| 30 public: | 31 public: |
| 31 explicit DropdownBackground(BrowserView* browser, | 32 explicit DropdownBackground(BrowserView* browser, |
| 32 const SkBitmap* left_alpha_mask, | 33 const gfx::ImageSkia* left_alpha_mask, |
| 33 const SkBitmap* right_alpha_mask); | 34 const gfx::ImageSkia* right_alpha_mask); |
| 34 virtual ~DropdownBackground() {} | 35 virtual ~DropdownBackground() {} |
| 35 | 36 |
| 36 // Overridden from views::Background. | 37 // Overridden from views::Background. |
| 37 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE; | 38 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE; |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 BrowserView* browser_view_; | 41 BrowserView* browser_view_; |
| 41 const SkBitmap* left_alpha_mask_; | 42 const gfx::ImageSkia* left_alpha_mask_; |
| 42 const SkBitmap* right_alpha_mask_; | 43 const gfx::ImageSkia* right_alpha_mask_; |
| 43 | 44 |
| 44 DISALLOW_COPY_AND_ASSIGN(DropdownBackground); | 45 DISALLOW_COPY_AND_ASSIGN(DropdownBackground); |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 DropdownBackground::DropdownBackground(BrowserView* browser_view, | 48 DropdownBackground::DropdownBackground(BrowserView* browser_view, |
| 48 const SkBitmap* left_alpha_mask, | 49 const gfx::ImageSkia* left_alpha_mask, |
| 49 const SkBitmap* right_alpha_mask) | 50 const gfx::ImageSkia* right_alpha_mask) |
| 50 : browser_view_(browser_view), | 51 : browser_view_(browser_view), |
| 51 left_alpha_mask_(left_alpha_mask), | 52 left_alpha_mask_(left_alpha_mask), |
| 52 right_alpha_mask_(right_alpha_mask) { | 53 right_alpha_mask_(right_alpha_mask) { |
| 53 } | 54 } |
| 54 | 55 |
| 55 void DropdownBackground::Paint(gfx::Canvas* canvas, views::View* view) const { | 56 void DropdownBackground::Paint(gfx::Canvas* canvas, views::View* view) const { |
| 56 // Find the offset from which to tile the toolbar background image. | 57 // Find the offset from which to tile the toolbar background image. |
| 57 // First, get the origin with respect to the screen. | 58 // First, get the origin with respect to the screen. |
| 58 gfx::Point origin = view->GetWidget()->GetWindowScreenBounds().origin(); | 59 gfx::Point origin = view->GetWidget()->GetWindowScreenBounds().origin(); |
| 59 // Now convert from screen to parent coordinates. | 60 // Now convert from screen to parent coordinates. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 OnPaintBackground(&animating_edges); | 116 OnPaintBackground(&animating_edges); |
| 116 OnPaintBorder(&animating_edges); | 117 OnPaintBorder(&animating_edges); |
| 117 canvas->DrawBitmapInt(animating_edges.ExtractBitmap(), bounds().x(), | 118 canvas->DrawBitmapInt(animating_edges.ExtractBitmap(), bounds().x(), |
| 118 animation_offset()); | 119 animation_offset()); |
| 119 } | 120 } |
| 120 } | 121 } |
| 121 | 122 |
| 122 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
| 123 // DropDownBarView, protected: | 124 // DropDownBarView, protected: |
| 124 | 125 |
| 125 void DropdownBarView::SetBackground(const SkBitmap* left_alpha_mask, | 126 void DropdownBarView::SetBackground(const gfx::ImageSkia* left_alpha_mask, |
| 126 const SkBitmap* right_alpha_mask) { | 127 const gfx::ImageSkia* right_alpha_mask) { |
| 127 set_background(new DropdownBackground(host()->browser_view(), left_alpha_mask, | 128 set_background(new DropdownBackground(host()->browser_view(), left_alpha_mask, |
| 128 right_alpha_mask)); | 129 right_alpha_mask)); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void DropdownBarView::SetBorder(int left_border_bitmap_id, | 132 void DropdownBarView::SetBorder(int left_border_bitmap_id, |
| 132 int middle_border_bitmap_id, | 133 int middle_border_bitmap_id, |
| 133 int right_border_bitmap_id) { | 134 int right_border_bitmap_id) { |
| 134 int border_bitmap_ids[3] = {left_border_bitmap_id, middle_border_bitmap_id, | 135 int border_bitmap_ids[3] = {left_border_bitmap_id, middle_border_bitmap_id, |
| 135 right_border_bitmap_id}; | 136 right_border_bitmap_id}; |
| 136 set_border(views::Border::CreateBorderPainter( | 137 set_border(views::Border::CreateBorderPainter( |
| 137 new views::HorizontalPainter(border_bitmap_ids))); | 138 new views::HorizontalPainter(border_bitmap_ids))); |
| 138 } | 139 } |
| OLD | NEW |