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

Side by Side Diff: chrome/browser/ui/views/infobars/infobar_container_view.cc

Issue 1800373002: [MD] replace infobar bottom solid line separator with a shadow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 9 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_container_view.h" 5 #include "chrome/browser/ui/views/infobars/infobar_container_view.h"
6 6
7 #include "chrome/browser/ui/infobar_container_delegate.h"
7 #include "chrome/browser/ui/view_ids.h" 8 #include "chrome/browser/ui/view_ids.h"
8 #include "chrome/browser/ui/views/infobars/infobar_view.h" 9 #include "chrome/browser/ui/views/infobars/infobar_view.h"
9 #include "chrome/grit/generated_resources.h" 10 #include "chrome/grit/generated_resources.h"
10 #include "ui/accessibility/ax_view_state.h" 11 #include "ui/accessibility/ax_view_state.h"
11 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/material_design/material_design_controller.h"
14 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/skia_util.h"
12 #include "ui/views/view_targeter.h" 16 #include "ui/views/view_targeter.h"
13 17
18 namespace {
19
20 // The content shadow is drawn in two stages. A darker, shorter shadow is
21 // blended with a taller, lighter shadow. The heights are in dp.
22 const int kSmallShadowHeight = 1;
23 const int kLargeShadowHeight = 3;
24 const SkAlpha kSmallShadowAlpha = 0x33;
25 const SkAlpha kLargeShadowAlpha = 0x1A;
26
27 class ContentShadow : public views::View {
28 public:
29 ContentShadow() {
30 SetPaintToLayer(true);
31 layer()->SetFillsBoundsOpaquely(false);
32 }
33 ~ContentShadow() override {}
34
35 protected:
36 // views::View:
37 void OnPaint(gfx::Canvas* canvas) override {
38 // The first shader (small shadow) blurs from 0 to kSmallShadowHeight.
39 SkPaint paint;
40 skia::RefPtr<SkShader> shader = gfx::CreateGradientShader(
41 0, kSmallShadowHeight, SkColorSetA(SK_ColorBLACK, kSmallShadowAlpha),
42 SkColorSetA(SK_ColorBLACK, SK_AlphaTRANSPARENT));
43 paint.setShader(shader.get());
44 gfx::Rect small_shadow_bounds = GetLocalBounds();
45 small_shadow_bounds.set_height(kSmallShadowHeight);
46 canvas->DrawRect(small_shadow_bounds, paint);
47
48 // The second shader (large shadow) is solid from 0 to kSmallShadowHeight
49 // (blending with the first shader) and then blurs from kSmallShadowHeight
50 // to kLargeShadowHeight.
51 shader = gfx::CreateGradientShader(
52 kSmallShadowHeight, height(),
53 SkColorSetA(SK_ColorBLACK, kLargeShadowAlpha),
54 SkColorSetA(SK_ColorBLACK, SK_AlphaTRANSPARENT));
55 paint.setShader(shader.get());
56 canvas->DrawRect(GetLocalBounds(), paint);
57 }
58
59 private:
60 DISALLOW_COPY_AND_ASSIGN(ContentShadow);
61 };
62
63 } // namespace
64
14 // static 65 // static
15 const char InfoBarContainerView::kViewClassName[] = "InfoBarContainerView"; 66 const char InfoBarContainerView::kViewClassName[] = "InfoBarContainerView";
16 67
17 InfoBarContainerView::InfoBarContainerView(Delegate* delegate) 68 InfoBarContainerView::InfoBarContainerView(Delegate* delegate)
18 : infobars::InfoBarContainer(delegate) { 69 : infobars::InfoBarContainer(delegate), content_shadow_(nullptr) {
19 set_id(VIEW_ID_INFO_BAR_CONTAINER); 70 set_id(VIEW_ID_INFO_BAR_CONTAINER);
20 SetEventTargeter(make_scoped_ptr(new views::ViewTargeter(this))); 71 if (ui::MaterialDesignController::IsModeMaterial()) {
72 content_shadow_ = new ContentShadow();
73 AddChildView(content_shadow_);
74 }
21 } 75 }
22 76
23 InfoBarContainerView::~InfoBarContainerView() { 77 InfoBarContainerView::~InfoBarContainerView() {
24 RemoveAllInfoBarsForDestruction(); 78 RemoveAllInfoBarsForDestruction();
25 } 79 }
26 80
27 gfx::Size InfoBarContainerView::GetPreferredSize() const { 81 gfx::Size InfoBarContainerView::GetPreferredSize() const {
28 int total_height; 82 int total_height;
29 GetVerticalOverlap(&total_height); 83 int overlap = GetVerticalOverlap(&total_height);
84 total_height -= overlap;
85
86 // No need to reserve space for the bottom bar's separator; the shadow is good
87 // enough.
88 if (ui::MaterialDesignController::IsModeMaterial())
89 total_height -= InfoBarContainerDelegate::kSeparatorLineHeight;
90
30 gfx::Size size(0, total_height); 91 gfx::Size size(0, total_height);
31 for (int i = 0; i < child_count(); ++i) 92 for (int i = 0; i < child_count(); ++i)
32 size.SetToMax(gfx::Size(child_at(i)->GetPreferredSize().width(), 0)); 93 size.SetToMax(gfx::Size(child_at(i)->GetPreferredSize().width(), 0));
33 return size; 94 return size;
34 } 95 }
35 96
36 const char* InfoBarContainerView::GetClassName() const { 97 const char* InfoBarContainerView::GetClassName() const {
37 return kViewClassName; 98 return kViewClassName;
38 } 99 }
39 100
40 void InfoBarContainerView::Layout() { 101 void InfoBarContainerView::Layout() {
41 int top = GetVerticalOverlap(NULL); 102 int top = 0;
42 103
43 for (int i = 0; i < child_count(); ++i) { 104 for (int i = 0; i < child_count(); ++i) {
105 if (child_at(i) == content_shadow_)
106 continue;
107
44 InfoBarView* child = static_cast<InfoBarView*>(child_at(i)); 108 InfoBarView* child = static_cast<InfoBarView*>(child_at(i));
45 top -= child->arrow_height(); 109 top -= child->arrow_height();
46 int child_height = child->total_height(); 110 int child_height = child->total_height();
111
112 // Trim off the bottom bar's separator; the shadow is good enough.
113 // The last infobar is the second to last child overall (followed by
114 // |content_shadow_|).
115 if (ui::MaterialDesignController::IsModeMaterial() &&
116 i == child_count() - 2) {
117 child_height -= InfoBarContainerDelegate::kSeparatorLineHeight;
118 }
47 child->SetBounds(0, top, width(), child_height); 119 child->SetBounds(0, top, width(), child_height);
48 top += child_height; 120 top += child_height;
49 } 121 }
122
123 if (ui::MaterialDesignController::IsModeMaterial())
124 content_shadow_->SetBounds(0, top, width(), kLargeShadowHeight);
50 } 125 }
51 126
52 void InfoBarContainerView::GetAccessibleState(ui::AXViewState* state) { 127 void InfoBarContainerView::GetAccessibleState(ui::AXViewState* state) {
53 state->role = ui::AX_ROLE_GROUP; 128 state->role = ui::AX_ROLE_GROUP;
54 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER); 129 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER);
55 } 130 }
56 131
57 void InfoBarContainerView::PlatformSpecificAddInfoBar( 132 void InfoBarContainerView::PlatformSpecificAddInfoBar(
58 infobars::InfoBar* infobar, 133 infobars::InfoBar* infobar,
59 size_t position) { 134 size_t position) {
60 AddChildViewAt(static_cast<InfoBarView*>(infobar), 135 AddChildViewAt(static_cast<InfoBarView*>(infobar),
61 static_cast<int>(position)); 136 static_cast<int>(position));
62 } 137 }
63 138
64 void InfoBarContainerView::PlatformSpecificRemoveInfoBar( 139 void InfoBarContainerView::PlatformSpecificRemoveInfoBar(
65 infobars::InfoBar* infobar) { 140 infobars::InfoBar* infobar) {
66 RemoveChildView(static_cast<InfoBarView*>(infobar)); 141 RemoveChildView(static_cast<InfoBarView*>(infobar));
67 } 142 }
68
69 bool InfoBarContainerView::DoesIntersectRect(const View* target,
70 const gfx::Rect& rect) const {
71 DCHECK_EQ(this, target);
72 // Only events that intersect the portion below the arrow are interesting.
73 gfx::Rect non_arrow_bounds = GetLocalBounds();
74 non_arrow_bounds.Inset(0, GetVerticalOverlap(nullptr), 0, 0);
75 return rect.Intersects(non_arrow_bounds);
76 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/infobar_container_view.h ('k') | chrome/browser/ui/views/infobars/infobar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698