Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/infobar_container_delegate.h" |
| 8 #include "chrome/browser/ui/view_ids.h" | 8 #include "chrome/browser/ui/view_ids.h" |
| 9 #include "chrome/browser/ui/views/infobars/infobar_view.h" | 9 #include "chrome/browser/ui/views/infobars/infobar_view.h" |
| 10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| 11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 12 #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" | 13 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
| 16 #include "ui/views/view_targeter.h" | 15 #include "ui/views/view_targeter.h" |
| 17 | 16 |
| 18 namespace { | 17 namespace { |
| 19 | 18 |
| 20 // The content shadow is drawn in two stages. A darker, shorter shadow is | 19 // 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. | 20 // blended with a taller, lighter shadow. The heights are in dp. |
| 22 const int kSmallShadowHeight = 1; | 21 const int kSmallShadowHeight = 1; |
| 23 const int kLargeShadowHeight = 3; | 22 const int kLargeShadowHeight = 3; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 }; | 58 }; |
| 60 | 59 |
| 61 } // namespace | 60 } // namespace |
| 62 | 61 |
| 63 // static | 62 // static |
| 64 const char InfoBarContainerView::kViewClassName[] = "InfoBarContainerView"; | 63 const char InfoBarContainerView::kViewClassName[] = "InfoBarContainerView"; |
| 65 | 64 |
| 66 InfoBarContainerView::InfoBarContainerView(Delegate* delegate) | 65 InfoBarContainerView::InfoBarContainerView(Delegate* delegate) |
| 67 : infobars::InfoBarContainer(delegate), content_shadow_(nullptr) { | 66 : infobars::InfoBarContainer(delegate), content_shadow_(nullptr) { |
| 68 set_id(VIEW_ID_INFO_BAR_CONTAINER); | 67 set_id(VIEW_ID_INFO_BAR_CONTAINER); |
| 69 if (ui::MaterialDesignController::IsModeMaterial()) { | 68 content_shadow_ = new ContentShadow(); |
|
Peter Kasting
2016/09/19 19:04:06
Nit: Might as well do this in the initializer list
Evan Stade
2016/09/19 20:06:02
Done.
| |
| 70 content_shadow_ = new ContentShadow(); | 69 AddChildView(content_shadow_); |
| 71 AddChildView(content_shadow_); | |
| 72 } | |
| 73 } | 70 } |
| 74 | 71 |
| 75 InfoBarContainerView::~InfoBarContainerView() { | 72 InfoBarContainerView::~InfoBarContainerView() { |
| 76 RemoveAllInfoBarsForDestruction(); | 73 RemoveAllInfoBarsForDestruction(); |
| 77 } | 74 } |
| 78 | 75 |
| 79 gfx::Size InfoBarContainerView::GetPreferredSize() const { | 76 gfx::Size InfoBarContainerView::GetPreferredSize() const { |
| 80 int total_height; | 77 int total_height; |
| 81 int overlap = GetVerticalOverlap(&total_height); | 78 int overlap = GetVerticalOverlap(&total_height); |
| 82 total_height -= overlap; | 79 total_height -= overlap; |
| 83 | 80 |
| 84 // No need to reserve space for the bottom bar's separator; the shadow is good | 81 // No need to reserve space for the bottom bar's separator; the shadow is good |
| 85 // enough. | 82 // enough. |
| 86 if (ui::MaterialDesignController::IsModeMaterial()) | 83 total_height -= InfoBarContainerDelegate::kSeparatorLineHeight; |
|
Peter Kasting
2016/09/19 19:04:06
Should we be doing this in GetVerticalOverlap() in
Evan Stade
2016/09/19 20:06:02
I'd be worried about affecting mac.
Peter Kasting
2016/09/19 20:12:48
Hmm. It would be nice to at least know how Mac wa
Evan Stade
2016/09/19 20:25:21
filed a bug for these two things
| |
| 87 total_height -= InfoBarContainerDelegate::kSeparatorLineHeight; | |
| 88 | 84 |
| 89 gfx::Size size(0, total_height); | 85 gfx::Size size(0, total_height); |
| 90 for (int i = 0; i < child_count(); ++i) | 86 for (int i = 0; i < child_count(); ++i) |
| 91 size.SetToMax(gfx::Size(child_at(i)->GetPreferredSize().width(), 0)); | 87 size.SetToMax(gfx::Size(child_at(i)->GetPreferredSize().width(), 0)); |
| 92 return size; | 88 return size; |
| 93 } | 89 } |
| 94 | 90 |
| 95 const char* InfoBarContainerView::GetClassName() const { | 91 const char* InfoBarContainerView::GetClassName() const { |
| 96 return kViewClassName; | 92 return kViewClassName; |
| 97 } | 93 } |
| 98 | 94 |
| 99 void InfoBarContainerView::Layout() { | 95 void InfoBarContainerView::Layout() { |
| 100 int top = 0; | 96 int top = 0; |
| 101 | 97 |
| 102 for (int i = 0; i < child_count(); ++i) { | 98 for (int i = 0; i < child_count(); ++i) { |
| 103 if (child_at(i) == content_shadow_) | 99 if (child_at(i) == content_shadow_) |
| 104 continue; | 100 continue; |
| 105 | 101 |
| 106 InfoBarView* child = static_cast<InfoBarView*>(child_at(i)); | 102 InfoBarView* child = static_cast<InfoBarView*>(child_at(i)); |
| 107 top -= child->arrow_height(); | 103 top -= child->arrow_height(); |
| 108 int child_height = child->total_height(); | 104 int child_height = child->total_height(); |
| 109 | 105 |
| 110 // Trim off the bottom bar's separator; the shadow is good enough. | 106 // Trim off the bottom bar's separator; the shadow is good enough. |
| 111 // The last infobar is the second to last child overall (followed by | 107 // The last infobar is the second to last child overall (followed by |
| 112 // |content_shadow_|). | 108 // |content_shadow_|). |
| 113 if (ui::MaterialDesignController::IsModeMaterial() && | 109 if (i == child_count() - 2) |
| 114 i == child_count() - 2) { | |
| 115 child_height -= InfoBarContainerDelegate::kSeparatorLineHeight; | 110 child_height -= InfoBarContainerDelegate::kSeparatorLineHeight; |
| 116 } | |
| 117 child->SetBounds(0, top, width(), child_height); | 111 child->SetBounds(0, top, width(), child_height); |
| 118 top += child_height; | 112 top += child_height; |
| 119 } | 113 } |
| 120 | 114 |
| 121 if (ui::MaterialDesignController::IsModeMaterial()) | 115 content_shadow_->SetBounds(0, top, width(), kLargeShadowHeight); |
| 122 content_shadow_->SetBounds(0, top, width(), kLargeShadowHeight); | |
| 123 } | 116 } |
| 124 | 117 |
| 125 void InfoBarContainerView::GetAccessibleState(ui::AXViewState* state) { | 118 void InfoBarContainerView::GetAccessibleState(ui::AXViewState* state) { |
| 126 state->role = ui::AX_ROLE_GROUP; | 119 state->role = ui::AX_ROLE_GROUP; |
| 127 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER); | 120 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_INFOBAR_CONTAINER); |
| 128 } | 121 } |
| 129 | 122 |
| 130 void InfoBarContainerView::PlatformSpecificAddInfoBar( | 123 void InfoBarContainerView::PlatformSpecificAddInfoBar( |
| 131 infobars::InfoBar* infobar, | 124 infobars::InfoBar* infobar, |
| 132 size_t position) { | 125 size_t position) { |
| 133 AddChildViewAt(static_cast<InfoBarView*>(infobar), | 126 AddChildViewAt(static_cast<InfoBarView*>(infobar), |
| 134 static_cast<int>(position)); | 127 static_cast<int>(position)); |
| 135 } | 128 } |
| 136 | 129 |
| 137 void InfoBarContainerView::PlatformSpecificRemoveInfoBar( | 130 void InfoBarContainerView::PlatformSpecificRemoveInfoBar( |
| 138 infobars::InfoBar* infobar) { | 131 infobars::InfoBar* infobar) { |
| 139 RemoveChildView(static_cast<InfoBarView*>(infobar)); | 132 RemoveChildView(static_cast<InfoBarView*>(infobar)); |
| 140 } | 133 } |
| OLD | NEW |