OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/extensions/extension_installed_bubble.h" | 5 #include "chrome/browser/views/extensions/extension_installed_bubble.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 92 |
93 if (type_ == ExtensionInstalledBubble::PAGE_ACTION) { | 93 if (type_ == ExtensionInstalledBubble::PAGE_ACTION) { |
94 info_ = new views::Label(l10n_util::GetString( | 94 info_ = new views::Label(l10n_util::GetString( |
95 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO)); | 95 IDS_EXTENSION_INSTALLED_PAGE_ACTION_INFO)); |
96 info_->SetFont(font); | 96 info_->SetFont(font); |
97 info_->SetMultiLine(true); | 97 info_->SetMultiLine(true); |
98 info_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 98 info_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
99 AddChildView(info_); | 99 AddChildView(info_); |
100 } | 100 } |
101 | 101 |
| 102 if (type_ == ExtensionInstalledBubble::OMNIBOX_KEYWORD) { |
| 103 info_ = new views::Label(l10n_util::GetStringF( |
| 104 IDS_EXTENSION_INSTALLED_OMNIBOX_KEYWORD_INFO, |
| 105 UTF8ToUTF16(extension->omnibox_keyword()))); |
| 106 info_->SetFont(font); |
| 107 info_->SetMultiLine(true); |
| 108 info_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 109 AddChildView(info_); |
| 110 } |
| 111 |
102 manage_ = new views::Label( | 112 manage_ = new views::Label( |
103 l10n_util::GetString(IDS_EXTENSION_INSTALLED_MANAGE_INFO)); | 113 l10n_util::GetString(IDS_EXTENSION_INSTALLED_MANAGE_INFO)); |
104 manage_->SetFont(font); | 114 manage_->SetFont(font); |
105 manage_->SetMultiLine(true); | 115 manage_->SetMultiLine(true); |
106 manage_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 116 manage_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
107 AddChildView(manage_); | 117 AddChildView(manage_); |
108 | 118 |
109 close_button_ = new views::ImageButton(this); | 119 close_button_ = new views::ImageButton(this); |
110 close_button_->SetImage(views::CustomButton::BS_NORMAL, | 120 close_button_->SetImage(views::CustomButton::BS_NORMAL, |
111 rb.GetBitmapNamed(IDR_CLOSE_BAR)); | 121 rb.GetBitmapNamed(IDR_CLOSE_BAR)); |
(...skipping 22 matching lines...) Expand all Loading... |
134 int width = kHorizOuterMargin; | 144 int width = kHorizOuterMargin; |
135 width += kIconSize; | 145 width += kIconSize; |
136 width += kPanelHorizMargin; | 146 width += kPanelHorizMargin; |
137 width += kRightColumnWidth; | 147 width += kRightColumnWidth; |
138 width += 2*kPanelHorizMargin; | 148 width += 2*kPanelHorizMargin; |
139 width += kHorizOuterMargin; | 149 width += kHorizOuterMargin; |
140 | 150 |
141 int height = kVertOuterMargin; | 151 int height = kVertOuterMargin; |
142 height += heading_->GetHeightForWidth(kRightColumnWidth); | 152 height += heading_->GetHeightForWidth(kRightColumnWidth); |
143 height += kVertInnerMargin; | 153 height += kVertInnerMargin; |
144 if (type_ == ExtensionInstalledBubble::PAGE_ACTION) { | 154 if (type_ == ExtensionInstalledBubble::PAGE_ACTION || |
| 155 type_ == ExtensionInstalledBubble::OMNIBOX_KEYWORD) { |
145 height += info_->GetHeightForWidth(kRightColumnWidth); | 156 height += info_->GetHeightForWidth(kRightColumnWidth); |
146 height += kVertInnerMargin; | 157 height += kVertInnerMargin; |
147 } | 158 } |
148 height += manage_->GetHeightForWidth(kRightColumnWidth); | 159 height += manage_->GetHeightForWidth(kRightColumnWidth); |
149 height += kVertOuterMargin; | 160 height += kVertOuterMargin; |
150 | 161 |
151 return gfx::Size(width, std::max(height, kIconSize + 2 * kVertOuterMargin)); | 162 return gfx::Size(width, std::max(height, kIconSize + 2 * kVertOuterMargin)); |
152 } | 163 } |
153 | 164 |
154 virtual void Layout() { | 165 virtual void Layout() { |
155 int x = kHorizOuterMargin; | 166 int x = kHorizOuterMargin; |
156 int y = kVertOuterMargin; | 167 int y = kVertOuterMargin; |
157 | 168 |
158 icon_->SetBounds(x, y, kIconSize, kIconSize); | 169 icon_->SetBounds(x, y, kIconSize, kIconSize); |
159 x += kIconSize; | 170 x += kIconSize; |
160 x += kPanelHorizMargin; | 171 x += kPanelHorizMargin; |
161 | 172 |
162 y += kRightcolumnVerticalShift; | 173 y += kRightcolumnVerticalShift; |
163 heading_->SizeToFit(kRightColumnWidth); | 174 heading_->SizeToFit(kRightColumnWidth); |
164 heading_->SetX(x); | 175 heading_->SetX(x); |
165 heading_->SetY(y); | 176 heading_->SetY(y); |
166 y += heading_->height(); | 177 y += heading_->height(); |
167 y += kVertInnerMargin; | 178 y += kVertInnerMargin; |
168 | 179 |
169 if (type_ == ExtensionInstalledBubble::PAGE_ACTION) { | 180 if (type_ == ExtensionInstalledBubble::PAGE_ACTION || |
| 181 type_ == ExtensionInstalledBubble::OMNIBOX_KEYWORD) { |
170 info_->SizeToFit(kRightColumnWidth); | 182 info_->SizeToFit(kRightColumnWidth); |
171 info_->SetX(x); | 183 info_->SetX(x); |
172 info_->SetY(y); | 184 info_->SetY(y); |
173 y += info_->height(); | 185 y += info_->height(); |
174 y += kVertInnerMargin; | 186 y += kVertInnerMargin; |
175 } | 187 } |
176 | 188 |
177 manage_->SizeToFit(kRightColumnWidth); | 189 manage_->SizeToFit(kRightColumnWidth); |
178 manage_->SetX(x); | 190 manage_->SetX(x); |
179 manage_->SetY(y); | 191 manage_->SetY(y); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 223 |
212 ExtensionInstalledBubble::ExtensionInstalledBubble(const Extension* extension, | 224 ExtensionInstalledBubble::ExtensionInstalledBubble(const Extension* extension, |
213 Browser *browser, | 225 Browser *browser, |
214 SkBitmap icon) | 226 SkBitmap icon) |
215 : extension_(extension), | 227 : extension_(extension), |
216 browser_(browser), | 228 browser_(browser), |
217 icon_(icon), | 229 icon_(icon), |
218 animation_wait_retries_(0) { | 230 animation_wait_retries_(0) { |
219 AddRef(); // Balanced in InfoBubbleClosing. | 231 AddRef(); // Balanced in InfoBubbleClosing. |
220 | 232 |
221 if (extension_->browser_action()) { | 233 if (!extension_->omnibox_keyword().empty()) { |
| 234 type_ = OMNIBOX_KEYWORD; |
| 235 } else if (extension_->browser_action()) { |
222 type_ = BROWSER_ACTION; | 236 type_ = BROWSER_ACTION; |
223 } else if (extension->page_action() && | 237 } else if (extension->page_action() && |
224 !extension->page_action()->default_icon_path().empty()) { | 238 !extension->page_action()->default_icon_path().empty()) { |
225 type_ = PAGE_ACTION; | 239 type_ = PAGE_ACTION; |
226 } else { | 240 } else { |
227 type_ = GENERIC; | 241 type_ = GENERIC; |
228 } | 242 } |
229 | 243 |
230 // |extension| has been initialized but not loaded at this point. We need | 244 // |extension| has been initialized but not loaded at this point. We need |
231 // to wait on showing the Bubble until not only the EXTENSION_LOADED gets | 245 // to wait on showing the Bubble until not only the EXTENSION_LOADED gets |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 if (!reference_view || !reference_view->IsVisible()) | 299 if (!reference_view || !reference_view->IsVisible()) |
286 reference_view = NULL; // fall back to app menu below. | 300 reference_view = NULL; // fall back to app menu below. |
287 } | 301 } |
288 } else if (type_ == PAGE_ACTION) { | 302 } else if (type_ == PAGE_ACTION) { |
289 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); | 303 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); |
290 location_bar_view->SetPreviewEnabledPageAction(extension_->page_action(), | 304 location_bar_view->SetPreviewEnabledPageAction(extension_->page_action(), |
291 true); // preview_enabled | 305 true); // preview_enabled |
292 reference_view = location_bar_view->GetPageActionView( | 306 reference_view = location_bar_view->GetPageActionView( |
293 extension_->page_action()); | 307 extension_->page_action()); |
294 DCHECK(reference_view); | 308 DCHECK(reference_view); |
| 309 } else if (type_ == OMNIBOX_KEYWORD) { |
| 310 LocationBarView* location_bar_view = browser_view->GetLocationBarView(); |
| 311 reference_view = location_bar_view; |
| 312 DCHECK(reference_view); |
295 } | 313 } |
296 | 314 |
297 // Default case. | 315 // Default case. |
298 if (reference_view == NULL) | 316 if (reference_view == NULL) |
299 reference_view = browser_view->GetToolbarView()->app_menu(); | 317 reference_view = browser_view->GetToolbarView()->app_menu(); |
300 | 318 |
301 gfx::Point origin; | 319 gfx::Point origin; |
302 views::View::ConvertPointToScreen(reference_view, &origin); | 320 views::View::ConvertPointToScreen(reference_view, &origin); |
303 gfx::Rect bounds = reference_view->bounds(); | 321 gfx::Rect bounds = reference_view->bounds(); |
304 bounds.set_x(origin.x()); | 322 bounds.set_origin(origin); |
305 bounds.set_y(origin.y()); | 323 BubbleBorder::ArrowLocation arrow_location = BubbleBorder::TOP_RIGHT; |
306 | 324 |
307 bubble_content_ = new InstalledBubbleContent(extension_, type_, | 325 // For omnibox keyword bubbles, move the arrow to point to the left edge |
308 &icon_); | 326 // of the omnibox, just to the right of the icon. |
| 327 if (type_ == OMNIBOX_KEYWORD) { |
| 328 bounds.set_origin( |
| 329 browser_view->GetLocationBarView()->GetLocationEntryOrigin()); |
| 330 bounds.set_width(0); |
| 331 arrow_location = BubbleBorder::TOP_LEFT; |
| 332 } |
| 333 |
| 334 bubble_content_ = new InstalledBubbleContent(extension_, type_, &icon_); |
309 InfoBubble* info_bubble = | 335 InfoBubble* info_bubble = |
310 InfoBubble::Show(browser_view->GetWidget(), bounds, | 336 InfoBubble::Show(browser_view->GetWidget(), bounds, arrow_location, |
311 BubbleBorder::TOP_RIGHT, | |
312 bubble_content_, this); | 337 bubble_content_, this); |
313 bubble_content_->set_info_bubble(info_bubble); | 338 bubble_content_->set_info_bubble(info_bubble); |
314 } | 339 } |
315 | 340 |
316 // InfoBubbleDelegate | 341 // InfoBubbleDelegate |
317 void ExtensionInstalledBubble::InfoBubbleClosing(InfoBubble* info_bubble, | 342 void ExtensionInstalledBubble::InfoBubbleClosing(InfoBubble* info_bubble, |
318 bool closed_by_escape) { | 343 bool closed_by_escape) { |
319 if (extension_ && type_ == PAGE_ACTION) { | 344 if (extension_ && type_ == PAGE_ACTION) { |
320 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow( | 345 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow( |
321 browser_->window()->GetNativeHandle()); | 346 browser_->window()->GetNativeHandle()); |
322 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( | 347 browser_view->GetLocationBarView()->SetPreviewEnabledPageAction( |
323 extension_->page_action(), | 348 extension_->page_action(), |
324 false); // preview_enabled | 349 false); // preview_enabled |
325 } | 350 } |
326 | 351 |
327 Release(); // Balanced in ctor. | 352 Release(); // Balanced in ctor. |
328 } | 353 } |
OLD | NEW |