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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/ui/global_error/global_error.h" | 10 #include "chrome/browser/ui/global_error/global_error.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 enum { | 28 enum { |
29 TAG_ACCEPT_BUTTON = 1, | 29 TAG_ACCEPT_BUTTON = 1, |
30 TAG_CANCEL_BUTTON, | 30 TAG_CANCEL_BUTTON, |
31 }; | 31 }; |
32 | 32 |
33 const int kMaxBubbleViewWidth = 262; | 33 const int kMaxBubbleViewWidth = 262; |
34 | 34 |
35 // The vertical inset of the wrench bubble anchor from the wrench menu button. | 35 // The vertical inset of the wrench bubble anchor from the wrench menu button. |
36 const int kAnchorVerticalInset = 5; | 36 const int kAnchorVerticalInset = 5; |
37 | 37 |
38 const int kBubblePadding = 6; | 38 const int kBubblePadding = 19; |
| 39 |
| 40 // Spacing between bubble text and buttons. |
| 41 const int kLabelToButtonVerticalSpacing = 14; |
39 | 42 |
40 } // namespace | 43 } // namespace |
41 | 44 |
42 // GlobalErrorBubbleViewBase --------------------------------------------------- | 45 // GlobalErrorBubbleViewBase --------------------------------------------------- |
43 | 46 |
44 // static | 47 // static |
45 GlobalErrorBubbleViewBase* GlobalErrorBubbleViewBase::ShowStandardBubbleView( | 48 GlobalErrorBubbleViewBase* GlobalErrorBubbleViewBase::ShowStandardBubbleView( |
46 Browser* browser, | 49 Browser* browser, |
47 const base::WeakPtr<GlobalErrorWithStandardBubble>& error) { | 50 const base::WeakPtr<GlobalErrorWithStandardBubble>& error) { |
48 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 51 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
(...skipping 11 matching lines...) Expand all Loading... |
60 // GlobalErrorBubbleView ------------------------------------------------------- | 63 // GlobalErrorBubbleView ------------------------------------------------------- |
61 | 64 |
62 GlobalErrorBubbleView::GlobalErrorBubbleView( | 65 GlobalErrorBubbleView::GlobalErrorBubbleView( |
63 views::View* anchor_view, | 66 views::View* anchor_view, |
64 views::BubbleBorder::Arrow arrow, | 67 views::BubbleBorder::Arrow arrow, |
65 Browser* browser, | 68 Browser* browser, |
66 const base::WeakPtr<GlobalErrorWithStandardBubble>& error) | 69 const base::WeakPtr<GlobalErrorWithStandardBubble>& error) |
67 : BubbleDelegateView(anchor_view, arrow), | 70 : BubbleDelegateView(anchor_view, arrow), |
68 browser_(browser), | 71 browser_(browser), |
69 error_(error) { | 72 error_(error) { |
| 73 // Set content margins to left-align the bubble text with the title. |
| 74 // BubbleFrameView adds enough padding below title, no top padding needed. |
| 75 set_margins(gfx::Insets(0, kBubblePadding, kBubblePadding, kBubblePadding)); |
| 76 |
70 // Compensate for built-in vertical padding in the anchor view's image. | 77 // Compensate for built-in vertical padding in the anchor view's image. |
71 set_anchor_view_insets( | 78 set_anchor_view_insets( |
72 gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0)); | 79 gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0)); |
73 | 80 |
74 std::vector<base::string16> message_strings(error_->GetBubbleViewMessages()); | 81 std::vector<base::string16> message_strings(error_->GetBubbleViewMessages()); |
75 std::vector<views::Label*> message_labels; | 82 std::vector<views::Label*> message_labels; |
76 for (size_t i = 0; i < message_strings.size(); ++i) { | 83 for (size_t i = 0; i < message_strings.size(); ++i) { |
77 views::Label* message_label = new views::Label(message_strings[i]); | 84 views::Label* message_label = new views::Label(message_strings[i]); |
78 message_label->SetMultiLine(true); | 85 message_label->SetMultiLine(true); |
79 message_label->SizeToFit(kMaxBubbleViewWidth); | 86 message_label->SizeToFit(kMaxBubbleViewWidth); |
(...skipping 18 matching lines...) Expand all Loading... |
98 scoped_ptr<views::LabelButton> cancel_button; | 105 scoped_ptr<views::LabelButton> cancel_button; |
99 if (!cancel_string.empty()) { | 106 if (!cancel_string.empty()) { |
100 cancel_button.reset(new views::LabelButton(this, cancel_string)); | 107 cancel_button.reset(new views::LabelButton(this, cancel_string)); |
101 cancel_button->SetStyle(views::Button::STYLE_BUTTON); | 108 cancel_button->SetStyle(views::Button::STYLE_BUTTON); |
102 cancel_button->set_tag(TAG_CANCEL_BUTTON); | 109 cancel_button->set_tag(TAG_CANCEL_BUTTON); |
103 } | 110 } |
104 | 111 |
105 views::GridLayout* layout = new views::GridLayout(this); | 112 views::GridLayout* layout = new views::GridLayout(this); |
106 SetLayoutManager(layout); | 113 SetLayoutManager(layout); |
107 | 114 |
108 // BubbleFrameView adds enough padding below title, no top padding needed. | |
109 layout->SetInsets(0, kBubblePadding, kBubblePadding, kBubblePadding); | |
110 | |
111 // First row, message labels. | 115 // First row, message labels. |
112 views::ColumnSet* cs = layout->AddColumnSet(0); | 116 views::ColumnSet* cs = layout->AddColumnSet(0); |
113 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 117 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
114 1, views::GridLayout::USE_PREF, 0, 0); | 118 1, views::GridLayout::USE_PREF, 0, 0); |
115 | 119 |
116 // Second row, accept and cancel button. | 120 // Second row, accept and cancel button. |
117 cs = layout->AddColumnSet(1); | 121 cs = layout->AddColumnSet(1); |
118 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | 122 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); |
119 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, | 123 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, |
120 0, views::GridLayout::USE_PREF, 0, 0); | 124 0, views::GridLayout::USE_PREF, 0, 0); |
121 if (cancel_button.get()) { | 125 if (cancel_button.get()) { |
122 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | 126 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
123 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, | 127 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, |
124 0, views::GridLayout::USE_PREF, 0, 0); | 128 0, views::GridLayout::USE_PREF, 0, 0); |
125 } | 129 } |
126 | 130 |
127 for (size_t i = 0; i < message_labels.size(); ++i) { | 131 for (size_t i = 0; i < message_labels.size(); ++i) { |
128 layout->StartRow(1, 0); | 132 layout->StartRow(1, 0); |
129 layout->AddView(message_labels[i]); | 133 layout->AddView(message_labels[i]); |
130 if (i < message_labels.size() - 1) | 134 if (i < message_labels.size() - 1) |
131 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 135 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
132 } | 136 } |
133 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); | 137 layout->AddPaddingRow(0, kLabelToButtonVerticalSpacing); |
134 | 138 |
135 layout->StartRow(0, 1); | 139 layout->StartRow(0, 1); |
136 layout->AddView(accept_button.release()); | 140 layout->AddView(accept_button.release()); |
137 if (cancel_button.get()) | 141 if (cancel_button.get()) |
138 layout->AddView(cancel_button.release()); | 142 layout->AddView(cancel_button.release()); |
139 | 143 |
140 // Adjust the message label size in case buttons are too long. | 144 // Adjust the message label size in case buttons are too long. |
141 for (size_t i = 0; i < message_labels.size(); ++i) | 145 for (size_t i = 0; i < message_labels.size(); ++i) |
142 message_labels[i]->SizeToFit(layout->GetPreferredSize(this).width()); | 146 message_labels[i]->SizeToFit(layout->GetPreferredSize(this).width()); |
143 | 147 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 error_->BubbleViewDidClose(browser_); | 189 error_->BubbleViewDidClose(browser_); |
186 } | 190 } |
187 | 191 |
188 bool GlobalErrorBubbleView::ShouldShowCloseButton() const { | 192 bool GlobalErrorBubbleView::ShouldShowCloseButton() const { |
189 return error_ && error_->ShouldShowCloseButton(); | 193 return error_ && error_->ShouldShowCloseButton(); |
190 } | 194 } |
191 | 195 |
192 void GlobalErrorBubbleView::CloseBubbleView() { | 196 void GlobalErrorBubbleView::CloseBubbleView() { |
193 GetWidget()->Close(); | 197 GetWidget()->Close(); |
194 } | 198 } |
OLD | NEW |