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

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

Issue 2613343002: Allow a View to specify a non-default native theme (i.e. different from (Closed)
Patch Set: no "override" Created 3 years, 11 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
« no previous file with comments | « no previous file | ui/views/view.h » ('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/infobars/confirm_infobar.h" 5 #include "chrome/browser/ui/views/infobars/confirm_infobar.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/ui/views/elevation_icon_setter.h" 12 #include "chrome/browser/ui/views/elevation_icon_setter.h"
13 #include "components/infobars/core/confirm_infobar_delegate.h" 13 #include "components/infobars/core/confirm_infobar_delegate.h"
14 #include "ui/base/material_design/material_design_controller.h" 14 #include "ui/base/material_design/material_design_controller.h"
15 #include "ui/base/window_open_disposition.h" 15 #include "ui/base/window_open_disposition.h"
16 #include "ui/native_theme/native_theme.h"
16 #include "ui/views/controls/button/label_button.h" 17 #include "ui/views/controls/button/label_button.h"
17 #include "ui/views/controls/button/md_text_button.h" 18 #include "ui/views/controls/button/md_text_button.h"
18 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
19 #include "ui/views/controls/link.h" 20 #include "ui/views/controls/link.h"
20 21
21 // InfoBarService ------------------------------------------------------------- 22 // InfoBarService -------------------------------------------------------------
22 23
23 std::unique_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( 24 std::unique_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar(
24 std::unique_ptr<ConfirmInfoBarDelegate> delegate) { 25 std::unique_ptr<ConfirmInfoBarDelegate> delegate) {
25 return base::MakeUnique<ConfirmInfoBar>(std::move(delegate)); 26 return base::MakeUnique<ConfirmInfoBar>(std::move(delegate));
26 } 27 }
27 28
28 29
29 // ConfirmInfoBar ------------------------------------------------------------- 30 // ConfirmInfoBar -------------------------------------------------------------
30 31
31 ConfirmInfoBar::ConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate> delegate) 32 ConfirmInfoBar::ConfirmInfoBar(std::unique_ptr<ConfirmInfoBarDelegate> delegate)
32 : InfoBarView(std::move(delegate)), 33 : InfoBarView(std::move(delegate)),
33 label_(nullptr), 34 label_(nullptr),
34 ok_button_(nullptr), 35 ok_button_(nullptr),
35 cancel_button_(nullptr), 36 cancel_button_(nullptr),
36 link_(nullptr) {} 37 link_(nullptr) {
38 // Always use the standard theme for the platform on infobars (infobars in
39 // incognito should have the same appearance as normal infobars).
40 SetNativeTheme(ui::NativeTheme::GetInstanceForNativeUi());
41 }
37 42
38 ConfirmInfoBar::~ConfirmInfoBar() { 43 ConfirmInfoBar::~ConfirmInfoBar() {
39 // Ensure |elevation_icon_setter_| is destroyed before |ok_button_|. 44 // Ensure |elevation_icon_setter_| is destroyed before |ok_button_|.
40 elevation_icon_setter_.reset(); 45 elevation_icon_setter_.reset();
41 } 46 }
42 47
43 void ConfirmInfoBar::Layout() { 48 void ConfirmInfoBar::Layout() {
44 InfoBarView::Layout(); 49 InfoBarView::Layout();
45 50
46 int x = StartX(); 51 int x = StartX();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ok_button_->SizeToPreferredSize(); 89 ok_button_->SizeToPreferredSize();
85 } 90 }
86 91
87 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { 92 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
88 cancel_button_ = views::MdTextButton::Create( 93 cancel_button_ = views::MdTextButton::Create(
89 this, 94 this,
90 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); 95 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL));
91 if (delegate->GetButtons() == ConfirmInfoBarDelegate::BUTTON_CANCEL) { 96 if (delegate->GetButtons() == ConfirmInfoBarDelegate::BUTTON_CANCEL) {
92 // Apply prominent styling only if the cancel button is the only button. 97 // Apply prominent styling only if the cancel button is the only button.
93 cancel_button_->SetProminent(true); 98 cancel_button_->SetProminent(true);
94 } else {
95 // Otherwise set the bg color to white and the text color to black.
96 // TODO(estade): These should be removed and moved into the native
97 // theme. Also, infobars should always use the normal (non-incognito)
98 // native theme.
99 cancel_button_->SetBgColorOverride(SK_ColorWHITE);
100 cancel_button_->SetEnabledTextColors(kTextColor);
101 } 99 }
102 AddViewToContentArea(cancel_button_); 100 AddViewToContentArea(cancel_button_);
103 cancel_button_->SizeToPreferredSize(); 101 cancel_button_->SizeToPreferredSize();
104 } 102 }
105 103
106 base::string16 link_text(delegate->GetLinkText()); 104 base::string16 link_text(delegate->GetLinkText());
107 link_ = CreateLink(link_text, this); 105 link_ = CreateLink(link_text, this);
108 AddViewToContentArea(link_); 106 AddViewToContentArea(link_);
109 } 107 }
110 108
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 145 }
148 146
149 int ConfirmInfoBar::NonLabelWidth() const { 147 int ConfirmInfoBar::NonLabelWidth() const {
150 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? 148 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ?
151 0 : kEndOfLabelSpacing; 149 0 : kEndOfLabelSpacing;
152 if (ok_button_) 150 if (ok_button_)
153 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); 151 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0);
154 width += cancel_button_ ? cancel_button_->width() : 0; 152 width += cancel_button_ ? cancel_button_->width() : 0;
155 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); 153 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing);
156 } 154 }
OLDNEW
« no previous file with comments | « no previous file | ui/views/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698