Chromium Code Reviews| 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/global_error_bubble_view.h" | 5 #include "chrome/browser/ui/views/global_error_bubble_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 : BubbleDialogDelegateView(anchor_view, arrow), | 67 : BubbleDialogDelegateView(anchor_view, arrow), |
| 68 browser_(browser), | 68 browser_(browser), |
| 69 error_(error) { | 69 error_(error) { |
| 70 if (!anchor_view) | 70 if (!anchor_view) |
| 71 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); | 71 SetAnchorRect(gfx::Rect(anchor_point, gfx::Size())); |
| 72 } | 72 } |
| 73 | 73 |
| 74 GlobalErrorBubbleView::~GlobalErrorBubbleView() {} | 74 GlobalErrorBubbleView::~GlobalErrorBubbleView() {} |
| 75 | 75 |
| 76 base::string16 GlobalErrorBubbleView::GetWindowTitle() const { | 76 base::string16 GlobalErrorBubbleView::GetWindowTitle() const { |
| 77 if (!error_) | |
| 78 return base::string16(); | |
| 77 return error_->GetBubbleViewTitle(); | 79 return error_->GetBubbleViewTitle(); |
| 78 } | 80 } |
| 79 | 81 |
| 80 gfx::ImageSkia GlobalErrorBubbleView::GetWindowIcon() { | 82 gfx::ImageSkia GlobalErrorBubbleView::GetWindowIcon() { |
| 81 gfx::Image image = error_->GetBubbleViewIcon(); | 83 gfx::Image image; |
| 82 DCHECK(!image.IsEmpty()); | 84 if (error_) { |
| 85 image = error_->GetBubbleViewIcon(); | |
| 86 DCHECK(!image.IsEmpty()); | |
| 87 } | |
| 83 return *image.ToImageSkia(); | 88 return *image.ToImageSkia(); |
| 84 } | 89 } |
| 85 | 90 |
| 86 bool GlobalErrorBubbleView::ShouldShowWindowIcon() const { | 91 bool GlobalErrorBubbleView::ShouldShowWindowIcon() const { |
| 87 return true; | 92 return true; |
| 88 } | 93 } |
| 89 | 94 |
| 90 void GlobalErrorBubbleView::WindowClosing() { | 95 void GlobalErrorBubbleView::WindowClosing() { |
| 91 if (error_) | 96 if (error_) |
| 92 error_->BubbleViewDidClose(browser_); | 97 error_->BubbleViewDidClose(browser_); |
| 93 } | 98 } |
| 94 | 99 |
| 100 // |error_| is assumed to be valid, and stay valid, at least until Init() | |
|
sky
2017/01/26 19:06:07
optional: This comment applies to Init(), so I wou
CJ
2017/01/27 00:44:05
Done.
| |
| 101 // returns. | |
| 95 void GlobalErrorBubbleView::Init() { | 102 void GlobalErrorBubbleView::Init() { |
| 96 // Compensate for built-in vertical padding in the anchor view's image. | 103 // Compensate for built-in vertical padding in the anchor view's image. |
| 97 set_anchor_view_insets(gfx::Insets( | 104 set_anchor_view_insets(gfx::Insets( |
| 98 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); | 105 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); |
| 99 | 106 |
| 100 std::vector<base::string16> message_strings(error_->GetBubbleViewMessages()); | 107 std::vector<base::string16> message_strings(error_->GetBubbleViewMessages()); |
| 101 std::vector<views::Label*> message_labels; | 108 std::vector<views::Label*> message_labels; |
| 102 for (size_t i = 0; i < message_strings.size(); ++i) { | 109 for (size_t i = 0; i < message_strings.size(); ++i) { |
| 103 views::Label* message_label = new views::Label(message_strings[i]); | 110 views::Label* message_label = new views::Label(message_strings[i]); |
| 104 message_label->SetMultiLine(true); | 111 message_label->SetMultiLine(true); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 122 } | 129 } |
| 123 | 130 |
| 124 // These bubbles show at times where activation is sporadic (like at startup, | 131 // These bubbles show at times where activation is sporadic (like at startup, |
| 125 // or a new window opening). Make sure the bubble doesn't disappear before the | 132 // or a new window opening). Make sure the bubble doesn't disappear before the |
| 126 // user sees it, if the bubble needs to be acknowledged. | 133 // user sees it, if the bubble needs to be acknowledged. |
| 127 set_close_on_deactivate(error_->ShouldCloseOnDeactivate()); | 134 set_close_on_deactivate(error_->ShouldCloseOnDeactivate()); |
| 128 } | 135 } |
| 129 | 136 |
| 130 void GlobalErrorBubbleView::UpdateButton(views::LabelButton* button, | 137 void GlobalErrorBubbleView::UpdateButton(views::LabelButton* button, |
| 131 ui::DialogButton type) { | 138 ui::DialogButton type) { |
| 132 BubbleDialogDelegateView::UpdateButton(button, type); | 139 if (error_) { |
| 133 if (type == ui::DIALOG_BUTTON_OK && | 140 BubbleDialogDelegateView::UpdateButton(button, type); |
| 134 error_->ShouldAddElevationIconToAcceptButton()) { | 141 if (type == ui::DIALOG_BUTTON_OK && |
| 135 elevation_icon_setter_.reset(new ElevationIconSetter( | 142 error_->ShouldAddElevationIconToAcceptButton()) { |
| 136 button, base::Bind(&GlobalErrorBubbleView::SizeToContents, | 143 elevation_icon_setter_.reset(new ElevationIconSetter( |
| 137 base::Unretained(this)))); | 144 button, base::Bind(&GlobalErrorBubbleView::SizeToContents, |
| 145 base::Unretained(this)))); | |
| 146 } | |
| 138 } | 147 } |
| 139 } | 148 } |
| 140 | 149 |
| 141 bool GlobalErrorBubbleView::ShouldShowCloseButton() const { | 150 bool GlobalErrorBubbleView::ShouldShowCloseButton() const { |
| 142 return error_ && error_->ShouldShowCloseButton(); | 151 return error_ && error_->ShouldShowCloseButton(); |
| 143 } | 152 } |
| 144 | 153 |
| 145 bool GlobalErrorBubbleView::ShouldDefaultButtonBeBlue() const { | 154 bool GlobalErrorBubbleView::ShouldDefaultButtonBeBlue() const { |
| 146 return true; | 155 return true; |
| 147 } | 156 } |
| 148 | 157 |
| 149 base::string16 GlobalErrorBubbleView::GetDialogButtonLabel( | 158 base::string16 GlobalErrorBubbleView::GetDialogButtonLabel( |
| 150 ui::DialogButton button) const { | 159 ui::DialogButton button) const { |
| 160 if (!error_) | |
| 161 return base::string16(); | |
| 151 return button == ui::DIALOG_BUTTON_OK | 162 return button == ui::DIALOG_BUTTON_OK |
| 152 ? error_->GetBubbleViewAcceptButtonLabel() | 163 ? error_->GetBubbleViewAcceptButtonLabel() |
| 153 : error_->GetBubbleViewCancelButtonLabel(); | 164 : error_->GetBubbleViewCancelButtonLabel(); |
| 154 } | 165 } |
| 155 | 166 |
| 156 int GlobalErrorBubbleView::GetDialogButtons() const { | 167 int GlobalErrorBubbleView::GetDialogButtons() const { |
| 168 if (!error_) | |
| 169 return ui::DIALOG_BUTTON_NONE; | |
| 157 return ui::DIALOG_BUTTON_OK | | 170 return ui::DIALOG_BUTTON_OK | |
| 158 (error_->GetBubbleViewCancelButtonLabel().empty() | 171 (error_->GetBubbleViewCancelButtonLabel().empty() |
| 159 ? 0 | 172 ? 0 |
| 160 : ui::DIALOG_BUTTON_CANCEL); | 173 : ui::DIALOG_BUTTON_CANCEL); |
| 161 } | 174 } |
| 162 | 175 |
| 163 bool GlobalErrorBubbleView::Cancel() { | 176 bool GlobalErrorBubbleView::Cancel() { |
| 164 error_->BubbleViewCancelButtonPressed(browser_); | 177 if (error_) |
| 178 error_->BubbleViewCancelButtonPressed(browser_); | |
| 165 return true; | 179 return true; |
| 166 } | 180 } |
| 167 | 181 |
| 168 bool GlobalErrorBubbleView::Accept() { | 182 bool GlobalErrorBubbleView::Accept() { |
| 169 error_->BubbleViewAcceptButtonPressed(browser_); | 183 if (error_) |
| 184 error_->BubbleViewAcceptButtonPressed(browser_); | |
| 170 return true; | 185 return true; |
| 171 } | 186 } |
| 172 | 187 |
| 173 bool GlobalErrorBubbleView::Close() { | 188 bool GlobalErrorBubbleView::Close() { |
| 174 // Don't fall through to either Cancel() or Accept(). | 189 // Don't fall through to either Cancel() or Accept(). |
| 175 return true; | 190 return true; |
| 176 } | 191 } |
| 177 | 192 |
| 178 void GlobalErrorBubbleView::CloseBubbleView() { | 193 void GlobalErrorBubbleView::CloseBubbleView() { |
| 179 GetWidget()->Close(); | 194 GetWidget()->Close(); |
| 180 } | 195 } |
| OLD | NEW |