Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: chrome/browser/ui/views/dropdown_bar_view.cc

Issue 1545023002: Relanding fix from ea9b0ba419a3598bdb7f7c62afdf4409afa73ab1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/dropdown_bar_view.h ('k') | chrome/browser/ui/views/find_bar_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/theme_resources.h" 10 #include "grit/theme_resources.h"
11 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "third_party/skia/include/core/SkRect.h" 12 #include "third_party/skia/include/core/SkRect.h"
13 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/canvas.h" 14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/image/image_skia.h" 15 #include "ui/gfx/image/image_skia.h"
16 #include "ui/views/background.h" 16 #include "ui/views/background.h"
17 #include "ui/views/border.h" 17 #include "ui/views/border.h"
18 #include "ui/views/painter.h" 18 #include "ui/views/painter.h"
19 #include "ui/views/widget/widget.h" 19 #include "ui/views/widget/widget.h"
20 20
21 namespace { 21 namespace {
22 22
23 // 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 // window during this animation; this is the height of the items we draw.
26 const int kAnimatingEdgeHeight = 5;
27
28 // Background to paint toolbar background with rounded corners. 23 // Background to paint toolbar background with rounded corners.
29 class DropdownBackground : public views::Background { 24 class DropdownBackground : public views::Background {
30 public: 25 public:
31 explicit DropdownBackground(BrowserView* browser, 26 explicit DropdownBackground(BrowserView* browser,
32 const gfx::ImageSkia* left_alpha_mask, 27 const gfx::ImageSkia* left_alpha_mask,
33 const gfx::ImageSkia* right_alpha_mask); 28 const gfx::ImageSkia* right_alpha_mask);
34 ~DropdownBackground() override {} 29 ~DropdownBackground() override {}
35 30
36 // Overridden from views::Background. 31 // Overridden from views::Background.
37 void Paint(gfx::Canvas* canvas, views::View* view) const override; 32 void Paint(gfx::Canvas* canvas, views::View* view) const override;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 0, 0, left_edge_width, height, false, paint); 75 0, 0, left_edge_width, height, false, paint);
81 76
82 // Draw right edge. 77 // Draw right edge.
83 int x_right_edge = view->bounds().width() - right_edge_width; 78 int x_right_edge = view->bounds().width() - right_edge_width;
84 canvas->DrawImageInt(*right_alpha_mask_, 0, 0, right_edge_width, 79 canvas->DrawImageInt(*right_alpha_mask_, 0, 0, right_edge_width,
85 mask_height, x_right_edge, 0, right_edge_width, height, false, paint); 80 mask_height, x_right_edge, 0, right_edge_width, height, false, paint);
86 } 81 }
87 82
88 } // namespace 83 } // namespace
89 84
90 DropdownBarView::DropdownBarView(DropdownBarHost* host) 85 DropdownBarView::DropdownBarView(DropdownBarHost* host) : host_(host) {}
91 : host_(host), animation_offset_(0) {}
92 86
93 DropdownBarView::~DropdownBarView() { 87 DropdownBarView::~DropdownBarView() {
94 } 88 }
95 89
96 //////////////////////////////////////////////////////////////////////////////// 90 ////////////////////////////////////////////////////////////////////////////////
97 // DropDownBarView, public:
98
99 void DropdownBarView::SetAnimationOffset(int offset) {
100 animation_offset_ = offset;
101 set_clip_insets(gfx::Insets(animation_offset_, 0, 0, 0));
102 }
103
104 // DropDownBarView, views::View overrides:
105 void DropdownBarView::OnPaint(gfx::Canvas* canvas) {
106 OnPaintBackground(canvas);
107 OnPaintBorder(canvas);
108
109 if (animation_offset() > 0) {
110 gfx::Canvas animating_edges(
111 gfx::Size(bounds().width(), kAnimatingEdgeHeight),
112 canvas->image_scale(), false);
113 canvas->Translate(bounds().OffsetFromOrigin());
114 OnPaintBackground(&animating_edges);
115 OnPaintBorder(&animating_edges);
116 canvas->DrawImageInt(gfx::ImageSkia(animating_edges.ExtractImageRep()),
117 bounds().x(), animation_offset());
118 }
119 }
120
121 ////////////////////////////////////////////////////////////////////////////////
122 // DropDownBarView, protected: 91 // DropDownBarView, protected:
123 92
124 void DropdownBarView::SetBackground(const gfx::ImageSkia* left_alpha_mask, 93 void DropdownBarView::SetBackground(const gfx::ImageSkia* left_alpha_mask,
125 const gfx::ImageSkia* right_alpha_mask) { 94 const gfx::ImageSkia* right_alpha_mask) {
126 set_background(new DropdownBackground(host()->browser_view(), left_alpha_mask, 95 set_background(new DropdownBackground(host()->browser_view(), left_alpha_mask,
127 right_alpha_mask)); 96 right_alpha_mask));
128 } 97 }
129 98
130 void DropdownBarView::SetBorderFromIds(int left_border_image_id, 99 void DropdownBarView::SetBorderFromIds(int left_border_image_id,
131 int middle_border_image_id, 100 int middle_border_image_id,
132 int right_border_image_id) { 101 int right_border_image_id) {
133 int border_image_ids[3] = {left_border_image_id, middle_border_image_id, 102 int border_image_ids[3] = {left_border_image_id, middle_border_image_id,
134 right_border_image_id}; 103 right_border_image_id};
135 SetBorder(views::Border::CreateBorderPainter( 104 SetBorder(views::Border::CreateBorderPainter(
136 new views::HorizontalPainter(border_image_ids), gfx::Insets())); 105 new views::HorizontalPainter(border_image_ids), gfx::Insets()));
137 } 106 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/dropdown_bar_view.h ('k') | chrome/browser/ui/views/find_bar_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698