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

Side by Side Diff: chrome/browser/cocoa/location_bar/location_bar_view_mac.mm

Issue 2805070: [Mac] First part of Omnibox decoration refactor. Enable ev bubble. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: comment clarification Created 10 years, 5 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
OLDNEW
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 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" 5 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h"
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/nsimage_cache_mac.h" 10 #include "base/nsimage_cache_mac.h"
11 #include "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/sys_string_conversions.h" 13 #include "base/sys_string_conversions.h"
14 #include "chrome/app/chrome_dll_resource.h" 14 #include "chrome/app/chrome_dll_resource.h"
15 #include "chrome/browser/alternate_nav_url_fetcher.h" 15 #include "chrome/browser/alternate_nav_url_fetcher.h"
16 #import "chrome/browser/app_controller_mac.h" 16 #import "chrome/browser/app_controller_mac.h"
17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" 17 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
18 #include "chrome/browser/browser_list.h" 18 #include "chrome/browser/browser_list.h"
19 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h" 19 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h"
20 #include "chrome/browser/cocoa/event_utils.h" 20 #include "chrome/browser/cocoa/event_utils.h"
21 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" 21 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h"
22 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" 22 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h"
23 #import "chrome/browser/cocoa/first_run_bubble_controller.h" 23 #import "chrome/browser/cocoa/first_run_bubble_controller.h"
24 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" 24 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h"
25 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" 25 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h"
26 #import "chrome/browser/cocoa/location_bar/ev_bubble_decoration.h"
27 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h"
28 #import "chrome/browser/cocoa/location_bar/selected_keyword_decoration.h"
26 #include "chrome/browser/command_updater.h" 29 #include "chrome/browser/command_updater.h"
27 #include "chrome/browser/content_setting_image_model.h" 30 #include "chrome/browser/content_setting_image_model.h"
28 #include "chrome/browser/content_setting_bubble_model.h" 31 #include "chrome/browser/content_setting_bubble_model.h"
29 #include "chrome/browser/extensions/extension_browser_event_router.h" 32 #include "chrome/browser/extensions/extension_browser_event_router.h"
30 #include "chrome/browser/extensions/extensions_service.h" 33 #include "chrome/browser/extensions/extensions_service.h"
31 #include "chrome/browser/extensions/extension_tabs_module.h" 34 #include "chrome/browser/extensions/extension_tabs_module.h"
32 #include "chrome/browser/location_bar_util.h" 35 #include "chrome/browser/location_bar_util.h"
33 #include "chrome/browser/profile.h" 36 #include "chrome/browser/profile.h"
34 #include "chrome/browser/search_engines/template_url.h" 37 #include "chrome/browser/search_engines/template_url.h"
35 #include "chrome/browser/search_engines/template_url_model.h" 38 #include "chrome/browser/search_engines/template_url_model.h"
36 #include "chrome/browser/tab_contents/navigation_entry.h" 39 #include "chrome/browser/tab_contents/navigation_entry.h"
37 #include "chrome/browser/tab_contents/tab_contents.h" 40 #include "chrome/browser/tab_contents/tab_contents.h"
38 #include "chrome/common/extensions/extension.h" 41 #include "chrome/common/extensions/extension.h"
39 #include "chrome/common/extensions/extension_action.h" 42 #include "chrome/common/extensions/extension_action.h"
40 #include "chrome/common/extensions/extension_resource.h" 43 #include "chrome/common/extensions/extension_resource.h"
41 #include "chrome/common/notification_service.h" 44 #include "chrome/common/notification_service.h"
42 #include "chrome/common/pref_names.h" 45 #include "chrome/common/pref_names.h"
43 #include "net/base/net_util.h" 46 #include "net/base/net_util.h"
44 #include "grit/generated_resources.h" 47 #include "grit/generated_resources.h"
45 #include "grit/theme_resources.h" 48 #include "grit/theme_resources.h"
46 #include "skia/ext/skia_utils_mac.h" 49 #include "skia/ext/skia_utils_mac.h"
47 #import "third_party/mozilla/NSPasteboard+Utils.h"
48 50
49 51
50 // TODO(shess): This code is mostly copied from the gtk 52 // TODO(shess): This code is mostly copied from the gtk
51 // implementation. Make sure it's all appropriate and flesh it out. 53 // implementation. Make sure it's all appropriate and flesh it out.
52 54
53 namespace {
54
55 // Values for the label colors for different security states.
56 static const CGFloat kEVSecureTextColorRedComponent = 0.03;
57 static const CGFloat kEVSecureTextColorGreenComponent = 0.58;
58 static const CGFloat kEVSecureTextColorBlueComponent = 0.0;
59 static const CGFloat kSecurityErrorTextColorRedComponent = 0.63;
60 static const CGFloat kSecurityErrorTextColorGreenComponent = 0.0;
61 static const CGFloat kSecurityErrorTextColorBlueComponent = 0.0;
62
63 } // namespace
64
65 LocationBarViewMac::LocationBarViewMac( 55 LocationBarViewMac::LocationBarViewMac(
66 AutocompleteTextField* field, 56 AutocompleteTextField* field,
67 CommandUpdater* command_updater, 57 CommandUpdater* command_updater,
68 ToolbarModel* toolbar_model, 58 ToolbarModel* toolbar_model,
69 Profile* profile, 59 Profile* profile,
70 Browser* browser) 60 Browser* browser)
71 : edit_view_(new AutocompleteEditViewMac(this, toolbar_model, profile, 61 : edit_view_(new AutocompleteEditViewMac(this, toolbar_model, profile,
72 command_updater, field)), 62 command_updater, field)),
73 command_updater_(command_updater), 63 command_updater_(command_updater),
74 field_(field), 64 field_(field),
75 disposition_(CURRENT_TAB), 65 disposition_(CURRENT_TAB),
76 location_icon_view_(this), 66 location_icon_decoration_(new LocationIconDecoration(this)),
77 security_label_view_(), 67 selected_keyword_decoration_(
68 new SelectedKeywordDecoration([field_ font])),
69 ev_bubble_decoration_(
70 new EVBubbleDecoration(location_icon_decoration_.get(),
71 [field_ font])),
78 star_icon_view_(command_updater), 72 star_icon_view_(command_updater),
79 page_action_views_(this, profile, toolbar_model), 73 page_action_views_(this, profile, toolbar_model),
80 profile_(profile), 74 profile_(profile),
81 browser_(browser), 75 browser_(browser),
82 toolbar_model_(toolbar_model), 76 toolbar_model_(toolbar_model),
83 transition_(PageTransition::TYPED), 77 transition_(PageTransition::TYPED),
84 first_run_bubble_(this) { 78 first_run_bubble_(this) {
85 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 79 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
86 ContentSettingImageView* content_setting_view = 80 ContentSettingImageView* content_setting_view =
87 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this, 81 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this,
88 profile_); 82 profile_);
89 content_setting_views_.push_back(content_setting_view); 83 content_setting_views_.push_back(content_setting_view);
90 content_setting_view->SetVisible(false); 84 content_setting_view->SetVisible(false);
91 } 85 }
92 86
93 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; 87 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
94 [cell setLocationIconView:&location_icon_view_];
95 [cell setSecurityLabelView:&security_label_view_];
96 [cell setStarIconView:&star_icon_view_]; 88 [cell setStarIconView:&star_icon_view_];
97 [cell setPageActionViewList:&page_action_views_]; 89 [cell setPageActionViewList:&page_action_views_];
98 [cell setContentSettingViewsList:&content_setting_views_]; 90 [cell setContentSettingViewsList:&content_setting_views_];
99 91
100 registrar_.Add(this, 92 registrar_.Add(this,
101 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, 93 NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
102 NotificationService::AllSources()); 94 NotificationService::AllSources());
103 } 95 }
104 96
105 LocationBarViewMac::~LocationBarViewMac() { 97 LocationBarViewMac::~LocationBarViewMac() {
106 // Disconnect from cell in case it outlives us. 98 // Disconnect from cell in case it outlives us.
107 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; 99 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
108 [cell setPageActionViewList:NULL]; 100 [cell setPageActionViewList:NULL];
109 [cell setLocationIconView:NULL];
110 [cell setSecurityLabelView:NULL];
111 [cell setStarIconView:NULL]; 101 [cell setStarIconView:NULL];
112 } 102 }
113 103
114 void LocationBarViewMac::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { 104 void LocationBarViewMac::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) {
115 // We need the browser window to be shown before we can show the bubble, but 105 // We need the browser window to be shown before we can show the bubble, but
116 // we get called before that's happened. 106 // we get called before that's happened.
117 Task* task = first_run_bubble_.NewRunnableMethod( 107 Task* task = first_run_bubble_.NewRunnableMethod(
118 &LocationBarViewMac::ShowFirstRunBubbleInternal, bubble_type); 108 &LocationBarViewMac::ShowFirstRunBubbleInternal, bubble_type);
119 MessageLoop::current()->PostTask(FROM_HERE, task); 109 MessageLoop::current()->PostTask(FROM_HERE, task);
120 } 110 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 176 }
187 } 177 }
188 178
189 void LocationBarViewMac::SaveStateToContents(TabContents* contents) { 179 void LocationBarViewMac::SaveStateToContents(TabContents* contents) {
190 // TODO(shess): Why SaveStateToContents vs SaveStateToTab? 180 // TODO(shess): Why SaveStateToContents vs SaveStateToTab?
191 edit_view_->SaveStateToTab(contents); 181 edit_view_->SaveStateToTab(contents);
192 } 182 }
193 183
194 void LocationBarViewMac::Update(const TabContents* contents, 184 void LocationBarViewMac::Update(const TabContents* contents,
195 bool should_restore_state) { 185 bool should_restore_state) {
196 SetIcon(edit_view_->GetIcon());
197 page_action_views_.RefreshViews(); 186 page_action_views_.RefreshViews();
198 RefreshContentSettingsViews(); 187 RefreshContentSettingsViews();
199 // AutocompleteEditView restores state if the tab is non-NULL. 188 // AutocompleteEditView restores state if the tab is non-NULL.
200 edit_view_->Update(should_restore_state ? contents : NULL); 189 edit_view_->Update(should_restore_state ? contents : NULL);
190 OnChanged();
201 } 191 }
202 192
203 void LocationBarViewMac::OnAutocompleteAccept(const GURL& url, 193 void LocationBarViewMac::OnAutocompleteAccept(const GURL& url,
204 WindowOpenDisposition disposition, 194 WindowOpenDisposition disposition,
205 PageTransition::Type transition, 195 PageTransition::Type transition,
206 const GURL& alternate_nav_url) { 196 const GURL& alternate_nav_url) {
207 if (!url.is_valid()) 197 if (!url.is_valid())
208 return; 198 return;
209 199
210 location_input_ = UTF8ToWide(url.spec()); 200 location_input_ = UTF8ToWide(url.spec());
(...skipping 17 matching lines...) Expand all
228 if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) { 218 if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) {
229 // I'm not sure this should be reachable, but I'm not also sure enough 219 // I'm not sure this should be reachable, but I'm not also sure enough
230 // that it shouldn't to stick in a NOTREACHED(). In any case, this is 220 // that it shouldn't to stick in a NOTREACHED(). In any case, this is
231 // harmless. 221 // harmless.
232 delete fetcher; 222 delete fetcher;
233 } else { 223 } else {
234 // The navigation controller will delete the fetcher. 224 // The navigation controller will delete the fetcher.
235 } 225 }
236 } 226 }
237 227
238 void LocationBarViewMac::OnChangedImpl(AutocompleteTextField* field,
239 const std::wstring& keyword,
240 const std::wstring& short_name,
241 const bool is_keyword_hint,
242 const bool is_extension_keyword,
243 NSImage* image) {
244 AutocompleteTextFieldCell* cell = [field autocompleteTextFieldCell];
245 const CGFloat availableWidth([field availableDecorationWidth]);
246
247 if (!keyword.empty() && !is_keyword_hint) {
248 // Keyword search mode. The text will be like "Search Engine:".
249 // "Engine" is a parameter to be replaced by text based on the
250 // keyword.
251
252 const std::wstring min_name(
253 location_bar_util::CalculateMinString(short_name));
254 NSString* partial_string = nil;
255 int message_id = is_extension_keyword ?
256 IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT;
257 if (!min_name.empty()) {
258 partial_string =
259 l10n_util::GetNSStringF(message_id, WideToUTF16(min_name));
260 }
261
262 NSString* keyword_string =
263 l10n_util::GetNSStringF(message_id, WideToUTF16(short_name));
264 [cell setKeywordString:keyword_string
265 partialString:partial_string
266 availableWidth:availableWidth];
267 } else if (!keyword.empty() && is_keyword_hint) {
268 // Keyword is a hint, like "Press [Tab] to search Engine". [Tab]
269 // is a parameter to be replaced by an image. "Engine" is a
270 // parameter to be replaced by text based on the keyword.
271 std::vector<size_t> content_param_offsets;
272 int message_id = is_extension_keyword ?
273 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT;
274 const std::wstring keyword_hint(
275 l10n_util::GetStringF(message_id,
276 std::wstring(), short_name,
277 &content_param_offsets));
278
279 // Should always be 2 offsets, see the comment in
280 // location_bar_view.cc after IDS_OMNIBOX_KEYWORD_HINT fetch.
281 DCHECK_EQ(content_param_offsets.size(), 2U);
282
283 // Where to put the [TAB] image.
284 const size_t split(content_param_offsets.front());
285
286 NSString* prefix = base::SysWideToNSString(keyword_hint.substr(0, split));
287 NSString* suffix = base::SysWideToNSString(keyword_hint.substr(split));
288
289 [cell setKeywordHintPrefix:prefix image:image suffix:suffix
290 availableWidth:availableWidth];
291 } else {
292 // Nothing interesting to show, plain old text field.
293 [cell clearKeywordAndHint];
294 }
295
296 // The field needs to re-layout if the visible decoration changed.
297 [field resetFieldEditorFrameIfNeeded];
298 }
299
300 void LocationBarViewMac::OnChanged() { 228 void LocationBarViewMac::OnChanged() {
301 // Update the location-bar icon. 229 // Update the location-bar icon.
302 SetIcon(edit_view_->GetIcon()); 230 const int resource_id = edit_view_->GetIcon();
303 231 NSImage* image = AutocompleteEditViewMac::ImageForResource(resource_id);
304 // Unfortunately, the unit-test Profile doesn't have the right stuff 232 location_icon_decoration_->SetImage(image);
305 // setup to do what GetKeywordName() needs to do. So do that out 233 ev_bubble_decoration_->SetImage(image);
306 // here where we have a Profile and pass it into OnChangedImpl(). 234 Layout();
307 const std::wstring keyword(edit_view_->model()->keyword());
308 std::wstring short_name;
309 bool is_extension_keyword = false;
310 if (!keyword.empty()) {
311 short_name = profile_->GetTemplateURLModel()->
312 GetKeywordShortName(keyword, &is_extension_keyword);
313 }
314
315 // TODO(shess): Implementation exported to a static so that it can
316 // be unit tested without having to setup the entire object. This
317 // makes me sad. I should fix that.
318 OnChangedImpl(field_,
319 keyword,
320 short_name,
321 edit_view_->model()->is_keyword_hint(),
322 is_extension_keyword,
323 GetTabButtonImage());
324 } 235 }
325 236
326 void LocationBarViewMac::OnInputInProgress(bool in_progress) { 237 void LocationBarViewMac::OnInputInProgress(bool in_progress) {
327 toolbar_model_->set_input_in_progress(in_progress); 238 toolbar_model_->set_input_in_progress(in_progress);
328 Update(NULL, false); 239 Update(NULL, false);
329 } 240 }
330 241
331 void LocationBarViewMac::OnSetFocus() { 242 void LocationBarViewMac::OnSetFocus() {
332 // Update the keyword and search hint states. 243 // Update the keyword and search hint states.
333 OnChanged(); 244 OnChanged();
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 NOTREACHED(); 351 NOTREACHED();
441 return; 352 return;
442 } 353 }
443 page_action_views_.OnMousePressed(NSZeroRect, index); 354 page_action_views_.OnMousePressed(NSZeroRect, index);
444 } 355 }
445 356
446 void LocationBarViewMac::SetEditable(bool editable) { 357 void LocationBarViewMac::SetEditable(bool editable) {
447 [field_ setEditable:editable ? YES : NO]; 358 [field_ setEditable:editable ? YES : NO];
448 star_icon_view_.SetVisible(editable); 359 star_icon_view_.SetVisible(editable);
449 UpdatePageActions(); 360 UpdatePageActions();
361 Layout();
450 } 362 }
451 363
452 bool LocationBarViewMac::IsEditable() { 364 bool LocationBarViewMac::IsEditable() {
453 return [field_ isEditable] ? true : false; 365 return [field_ isEditable] ? true : false;
454 } 366 }
455 367
456 void LocationBarViewMac::SetStarred(bool starred) { 368 void LocationBarViewMac::SetStarred(bool starred) {
457 star_icon_view_.SetStarred(starred); 369 star_icon_view_.SetStarred(starred);
370
371 // TODO(shess): The field-editor frame and cursor rects should not
372 // change, here.
458 [field_ updateCursorAndToolTipRects]; 373 [field_ updateCursorAndToolTipRects];
459 [field_ resetFieldEditorFrameIfNeeded]; 374 [field_ resetFieldEditorFrameIfNeeded];
460 [field_ setNeedsDisplay:YES]; 375 [field_ setNeedsDisplay:YES];
461 } 376 }
462 377
463 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const { 378 NSPoint LocationBarViewMac::GetBookmarkBubblePoint() const {
464 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; 379 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
465 NSRect frame = [cell starIconFrameForFrame:[field_ bounds]]; 380 NSRect frame = [cell starIconFrameForFrame:[field_ bounds]];
466 frame = [field_ convertRect:frame toView:nil]; 381 frame = [field_ convertRect:frame toView:nil];
467 382
468 // Star is not exactly centered horizontally, and the tip should 383 // Star is not exactly centered horizontally, and the tip should
469 // point to the visual bottom of the star, not the middle. 384 // point to the visual bottom of the star, not the middle.
470 return NSMakePoint(NSMidX(frame), NSMinY(frame) + 4.0); 385 return NSMakePoint(NSMidX(frame), NSMinY(frame) + 4.0);
471 } 386 }
472 387
473 NSImage* LocationBarViewMac::GetTabButtonImage() { 388 NSImage* LocationBarViewMac::GetTabButtonImage() {
474 if (!tab_button_image_) { 389 if (!tab_button_image_) {
475 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance(). 390 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance().
476 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); 391 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB);
477 if (skiaBitmap) { 392 if (skiaBitmap) {
478 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]); 393 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]);
479 } 394 }
480 } 395 }
481 return tab_button_image_; 396 return tab_button_image_;
482 } 397 }
483 398
484 void LocationBarViewMac::SetIcon(int resource_id) {
485 DCHECK(resource_id != 0);
486
487 // The icon is always visible except when there is a keyword hint.
488 if (!edit_view_->model()->keyword().empty() &&
489 !edit_view_->model()->is_keyword_hint()) {
490 location_icon_view_.SetVisible(false);
491 } else {
492 NSImage* image = AutocompleteEditViewMac::ImageForResource(resource_id);
493 location_icon_view_.SetImage(image);
494 location_icon_view_.SetVisible(true);
495 SetSecurityLabel();
496 }
497 [field_ resetFieldEditorFrameIfNeeded];
498 }
499
500 void LocationBarViewMac::SetSecurityLabel() {
501 if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) {
502 std::wstring security_info_text(toolbar_model_->GetEVCertName());
503 NSString* icon_label = base::SysWideToNSString(security_info_text);
504 NSColor* color =
505 [NSColor colorWithCalibratedRed:kEVSecureTextColorRedComponent
506 green:kEVSecureTextColorGreenComponent
507 blue:kEVSecureTextColorBlueComponent
508 alpha:1.0];
509 security_label_view_.SetLabel(icon_label, [field_ font], color);
510 security_label_view_.SetVisible(true);
511 } else {
512 security_label_view_.SetLabel(nil, nil, nil);
513 security_label_view_.SetVisible(false);
514 }
515 }
516
517 void LocationBarViewMac::Observe(NotificationType type, 399 void LocationBarViewMac::Observe(NotificationType type,
518 const NotificationSource& source, 400 const NotificationSource& source,
519 const NotificationDetails& details) { 401 const NotificationDetails& details) {
520 switch (type.value) { 402 switch (type.value) {
521 case NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED: { 403 case NotificationType::EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED: {
522 TabContents* contents = GetTabContents(); 404 TabContents* contents = GetTabContents();
523 if (Details<TabContents>(contents) != details) 405 if (Details<TabContents>(contents) != details)
524 return; 406 return;
525 407
526 [field_ updateCursorAndToolTipRects]; 408 [field_ updateCursorAndToolTipRects];
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 return NSZeroSize; 470 return NSZeroSize;
589 } 471 }
590 472
591 NSSize LocationBarViewMac::LocationBarImageView::GetImageSize() const { 473 NSSize LocationBarViewMac::LocationBarImageView::GetImageSize() const {
592 NSImage* image = GetImage(); 474 NSImage* image = GetImage();
593 if (image) 475 if (image)
594 return [image size]; 476 return [image size];
595 return GetDefaultImageSize(); 477 return GetDefaultImageSize();
596 } 478 }
597 479
598 // LocationIconView ------------------------------------------------------------
599
600 LocationBarViewMac::LocationIconView::LocationIconView(
601 LocationBarViewMac* owner)
602 : owner_(owner) {
603 }
604
605 LocationBarViewMac::LocationIconView::~LocationIconView() {}
606
607 void LocationBarViewMac::LocationIconView::OnMousePressed(NSRect bounds) {
608 // Do not show page info if the user has been editing the location
609 // bar, or the location bar is at the NTP.
610 if (owner_->location_entry()->IsEditingOrEmpty())
611 return;
612
613 TabContents* tab = owner_->GetTabContents();
614 NavigationEntry* nav_entry = tab->controller().GetActiveEntry();
615 if (!nav_entry) {
616 NOTREACHED();
617 return;
618 }
619 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true);
620 }
621
622 bool LocationBarViewMac::LocationIconView::IsDraggable() {
623 // Do not drag if the user has been editing the location bar, or the
624 // location bar is at the NTP.
625 if (owner_->location_entry()->IsEditingOrEmpty())
626 return false;
627
628 return true;
629 }
630
631 NSPasteboard* LocationBarViewMac::LocationIconView::GetDragPasteboard() {
632 TabContents* tab = owner_->GetTabContents();
633 DCHECK(tab);
634
635 NSString* url = base::SysUTF8ToNSString(tab->GetURL().spec());
636 NSString* title = base::SysUTF16ToNSString(tab->GetTitle());
637
638 NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
639 [pboard declareURLPasteboardWithAdditionalTypes:[NSArray array]
640 owner:nil];
641 [pboard setDataForURL:url title:title];
642 return pboard;
643 }
644
645 // StarIconView----------------------------------------------------------------- 480 // StarIconView-----------------------------------------------------------------
646 481
647 LocationBarViewMac::StarIconView::StarIconView(CommandUpdater* command_updater) 482 LocationBarViewMac::StarIconView::StarIconView(CommandUpdater* command_updater)
648 : command_updater_(command_updater) { 483 : command_updater_(command_updater) {
649 SetVisible(true); 484 SetVisible(true);
650 SetStarred(false); 485 SetStarred(false);
651 } 486 }
652 487
653 void LocationBarViewMac::StarIconView::SetStarred(bool starred) { 488 void LocationBarViewMac::StarIconView::SetStarred(bool starred) {
654 if (starred) { 489 if (starred) {
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 ++result; 842 ++result;
1008 } 843 }
1009 return result; 844 return result;
1010 } 845 }
1011 846
1012 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame, 847 void LocationBarViewMac::PageActionViewList::OnMousePressed(NSRect iconFrame,
1013 size_t index) { 848 size_t index) {
1014 ViewAt(index)->OnMousePressed(iconFrame); 849 ViewAt(index)->OnMousePressed(iconFrame);
1015 } 850 }
1016 851
852 // TODO(shess): This function should over time grow to closely match
853 // the views Layout() function.
854 void LocationBarViewMac::Layout() {
855 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
856
857 // Reset the left-hand decorations.
858 // TODO(shess): Shortly, this code will live somewhere else, like in
859 // the constructor. I am still wrestling with how best to deal with
860 // right-hand decorations, which are not a static set.
861 [cell clearDecorations];
862 [cell addLeftDecoration:location_icon_decoration_.get()];
863 [cell addLeftDecoration:selected_keyword_decoration_.get()];
864 [cell addLeftDecoration:ev_bubble_decoration_.get()];
865
866 // By default only the location icon is visible.
867 location_icon_decoration_->SetVisible(true);
868 selected_keyword_decoration_->SetVisible(false);
869 ev_bubble_decoration_->SetVisible(false);
870
871 // Get the keyword to use for keyword-search and hinting.
872 const std::wstring keyword(edit_view_->model()->keyword());
873 std::wstring short_name;
874 bool is_extension_keyword = false;
875 if (!keyword.empty()) {
876 short_name = profile_->GetTemplateURLModel()->
877 GetKeywordShortName(keyword, &is_extension_keyword);
878 }
879
880 const bool is_keyword_hint = edit_view_->model()->is_keyword_hint();
881
882 if (!keyword.empty() && !is_keyword_hint) {
883 // Switch from location icon to keyword mode.
884 location_icon_decoration_->SetVisible(false);
885 selected_keyword_decoration_->SetVisible(true);
886
887 selected_keyword_decoration_->SetKeyword(short_name, is_extension_keyword);
888
889 // TODO(shess): This goes away once the hints are decorations.
890 [cell clearHint];
891 } else if (toolbar_model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) {
892 // Switch from location icon to show the EV bubble instead.
893 location_icon_decoration_->SetVisible(false);
894 ev_bubble_decoration_->SetVisible(true);
895
896 std::wstring label(toolbar_model_->GetEVCertName());
897 ev_bubble_decoration_->SetLabel(base::SysWideToNSString(label));
898
899 // TODO(shess): This goes away once the hints are decorations.
900 [cell clearHint];
901 } else if (!keyword.empty() && is_keyword_hint) {
902 // Keyword is a hint, like "Press [Tab] to search Engine". [Tab]
903 // is a parameter to be replaced by an image. "Engine" is a
904 // parameter to be replaced by text based on the keyword.
905 std::vector<size_t> content_param_offsets;
906 int message_id = is_extension_keyword ?
907 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT;
908 const std::wstring keyword_hint(
909 l10n_util::GetStringF(message_id,
910 std::wstring(), short_name,
911 &content_param_offsets));
912
913 // Should always be 2 offsets, see the comment in
914 // location_bar_view.cc after IDS_OMNIBOX_KEYWORD_HINT fetch.
915 DCHECK_EQ(content_param_offsets.size(), 2U);
916
917 // Where to put the [TAB] image.
918 const size_t split(content_param_offsets.front());
919
920 NSString* prefix = base::SysWideToNSString(keyword_hint.substr(0, split));
921 NSString* suffix = base::SysWideToNSString(keyword_hint.substr(split));
922
923 NSImage* image = GetTabButtonImage();
924 const CGFloat availableWidth([field_ availableDecorationWidth]);
925 [cell setKeywordHintPrefix:prefix image:image suffix:suffix
926 availableWidth:availableWidth];
927 } else {
928 // Nothing interesting to show, plain old text field.
929 [cell clearHint];
930 }
931
932 // These need to change anytime the layout changes.
933 // TODO(shess): Anytime the field editor might have changed, the
934 // cursor rects almost certainly should have changed. The tooltips
935 // might change even when the rects don't change.
936 [field_ resetFieldEditorFrameIfNeeded];
937 [field_ updateCursorAndToolTipRects];
938
939 [field_ setNeedsDisplay:YES];
940 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698