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

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

Issue 348069: Restoring r29827.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/location_bar_view_mac.h ('k') | skia/ext/skia_utils_mac.mm » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_view_mac.h" 5 #import "chrome/browser/cocoa/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/string_util.h" 9 #include "base/string_util.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
11 #include "chrome/app/chrome_dll_resource.h" 11 #include "chrome/app/chrome_dll_resource.h"
12 #include "chrome/browser/alternate_nav_url_fetcher.h" 12 #include "chrome/browser/alternate_nav_url_fetcher.h"
13 #import "chrome/browser/app_controller_mac.h" 13 #import "chrome/browser/app_controller_mac.h"
14 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" 14 #import "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
15 #include "chrome/browser/browser_list.h"
15 #import "chrome/browser/cocoa/autocomplete_text_field.h" 16 #import "chrome/browser/cocoa/autocomplete_text_field.h"
16 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" 17 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h"
17 #include "chrome/browser/cocoa/event_utils.h" 18 #include "chrome/browser/cocoa/event_utils.h"
18 #include "chrome/browser/command_updater.h" 19 #include "chrome/browser/command_updater.h"
19 #include "chrome/browser/profile.h" 20 #include "chrome/browser/profile.h"
20 #include "chrome/browser/search_engines/template_url.h" 21 #include "chrome/browser/search_engines/template_url.h"
21 #include "chrome/browser/search_engines/template_url_model.h" 22 #include "chrome/browser/search_engines/template_url_model.h"
23 #include "chrome/browser/tab_contents/navigation_entry.h"
24 #include "chrome/browser/tab_contents/tab_contents.h"
22 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h" 26 #include "grit/theme_resources.h"
24 #include "skia/ext/skia_utils_mac.h" 27 #include "skia/ext/skia_utils_mac.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 28 #include "third_party/skia/include/core/SkBitmap.h"
26 29
27 // TODO(shess): This code is mostly copied from the gtk 30 // TODO(shess): This code is mostly copied from the gtk
28 // implementation. Make sure it's all appropriate and flesh it out. 31 // implementation. Make sure it's all appropriate and flesh it out.
29 32
30 namespace { 33 namespace {
31 34
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 AutocompleteTextField* field, 77 AutocompleteTextField* field,
75 const BubblePositioner* bubble_positioner, 78 const BubblePositioner* bubble_positioner,
76 CommandUpdater* command_updater, 79 CommandUpdater* command_updater,
77 ToolbarModel* toolbar_model, 80 ToolbarModel* toolbar_model,
78 Profile* profile) 81 Profile* profile)
79 : edit_view_(new AutocompleteEditViewMac(this, bubble_positioner, 82 : edit_view_(new AutocompleteEditViewMac(this, bubble_positioner,
80 toolbar_model, profile, command_updater, field)), 83 toolbar_model, profile, command_updater, field)),
81 command_updater_(command_updater), 84 command_updater_(command_updater),
82 field_(field), 85 field_(field),
83 disposition_(CURRENT_TAB), 86 disposition_(CURRENT_TAB),
87 security_image_view_(profile, toolbar_model),
84 profile_(profile), 88 profile_(profile),
85 toolbar_model_(toolbar_model), 89 toolbar_model_(toolbar_model),
86 transition_(PageTransition::TYPED) { 90 transition_(PageTransition::TYPED) {
91 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
92 [cell setSecurityImageView:&security_image_view_];
87 } 93 }
88 94
89 LocationBarViewMac::~LocationBarViewMac() { 95 LocationBarViewMac::~LocationBarViewMac() {
90 // TODO(shess): Placeholder for omnibox changes. 96 // TODO(shess): Placeholder for omnibox changes.
91 } 97 }
92 98
93 std::wstring LocationBarViewMac::GetInputString() const { 99 std::wstring LocationBarViewMac::GetInputString() const {
94 return location_input_; 100 return location_input_;
95 } 101 }
96 102
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 if (!tab_button_image_) { 319 if (!tab_button_image_) {
314 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance(). 320 SkBitmap* skiaBitmap = ResourceBundle::GetSharedInstance().
315 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB); 321 GetBitmapNamed(IDR_LOCATION_BAR_KEYWORD_HINT_TAB);
316 if (skiaBitmap) { 322 if (skiaBitmap) {
317 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]); 323 tab_button_image_.reset([gfx::SkBitmapToNSImage(*skiaBitmap) retain]);
318 } 324 }
319 } 325 }
320 return tab_button_image_; 326 return tab_button_image_;
321 } 327 }
322 328
323 void LocationBarViewMac::SetSecurityIcon(ToolbarModel::Icon security_icon) { 329 void LocationBarViewMac::SetSecurityIconLabel() {
324 std::wstring info_text, info_tooltip; 330 std::wstring info_text;
331 std::wstring info_tooltip;
325 ToolbarModel::InfoTextType info_text_type = 332 ToolbarModel::InfoTextType info_text_type =
326 toolbar_model_->GetInfoText(&info_text, &info_tooltip); 333 toolbar_model_->GetInfoText(&info_text, &info_tooltip);
327 NSColor* color = nil;
328 NSString* icon_label = nil;
329 if (info_text_type == ToolbarModel::INFO_EV_TEXT) { 334 if (info_text_type == ToolbarModel::INFO_EV_TEXT) {
330 icon_label = base::SysWideToNSString(info_text); 335 NSString* icon_label = base::SysWideToNSString(info_text);
331 color = 336 NSColor* color = [NSColor colorWithCalibratedRed:kEvTextColorRedComponent
332 [NSColor colorWithCalibratedRed:kEvTextColorRedComponent 337 green:kEvTextColorGreenComponent
333 green:kEvTextColorGreenComponent 338 blue:kEvTextColorBlueComponent
334 blue:kEvTextColorBlueComponent 339 alpha:1.0];
335 alpha:1.0]; 340 security_image_view_.SetLabel(icon_label, [field_ font], color);
341 } else {
342 security_image_view_.SetLabel(nil, nil, nil);
336 } 343 }
344 }
337 345
338 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 346 void LocationBarViewMac::SetSecurityIcon(ToolbarModel::Icon icon) {
339 AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell]; 347 switch (icon) {
340 switch (security_icon) {
341 case ToolbarModel::LOCK_ICON: 348 case ToolbarModel::LOCK_ICON:
342 [cell setHintIcon:rb.GetNSImageNamed(IDR_LOCK) 349 security_image_view_.SetImageShown(SecurityImageView::LOCK);
343 label:icon_label 350 security_image_view_.SetVisible(true);
344 color:color]; 351 SetSecurityIconLabel();
345 break; 352 break;
346 case ToolbarModel::WARNING_ICON: 353 case ToolbarModel::WARNING_ICON:
347 [cell setHintIcon:rb.GetNSImageNamed(IDR_WARNING) 354 security_image_view_.SetImageShown(SecurityImageView::WARNING);
348 label:icon_label 355 security_image_view_.SetVisible(true);
349 color:color]; 356 SetSecurityIconLabel();
350 break; 357 break;
351 case ToolbarModel::NO_ICON: 358 case ToolbarModel::NO_ICON:
352 [cell setHintIcon:nil label:nil color:nil]; 359 security_image_view_.SetVisible(false);
360 break;
361 default:
362 NOTREACHED();
363 security_image_view_.SetVisible(false);
364 break;
365 }
366 [field_ resetFieldEditorFrameIfNeeded];
367 }
368
369 // LocationBarImageView---------------------------------------------------------
370
371 void LocationBarViewMac::LocationBarImageView::SetImage(NSImage* image) {
372 image_.reset([image retain]);
373 }
374
375 void LocationBarViewMac::LocationBarImageView::SetLabel(NSString* text,
376 NSFont* baseFont,
377 NSColor* color) {
378 // Create an attributed string for the label, if a label was given.
379 label_.reset();
380 if (text) {
381 DCHECK(color);
382 DCHECK(baseFont);
383 NSFont* font = [NSFont fontWithDescriptor:[baseFont fontDescriptor]
384 size:[baseFont pointSize] - 2.0];
385 NSDictionary* attributes =
386 [NSDictionary dictionaryWithObjectsAndKeys:
387 color, NSForegroundColorAttributeName,
388 font, NSFontAttributeName,
389 NULL];
390 NSAttributedString* attrStr =
391 [[NSAttributedString alloc] initWithString:text attributes:attributes];
392 label_.reset(attrStr);
393 }
394 }
395
396 void LocationBarViewMac::LocationBarImageView::SetVisible(bool visible) {
397 DCHECK(!visible || image_);
398 visible_ = visible;
399 }
400
401 // SecurityImageView------------------------------------------------------------
402
403 LocationBarViewMac::SecurityImageView::SecurityImageView(
404 Profile* profile,
405 ToolbarModel* model)
406 : lock_icon_(nil),
407 warning_icon_(nil),
408 profile_(profile),
409 model_(model) {}
410
411 LocationBarViewMac::SecurityImageView::~SecurityImageView() {}
412
413 void LocationBarViewMac::SecurityImageView::SetImageShown(Image image) {
414 switch (image) {
415 case LOCK:
416 if (!lock_icon_.get()) {
417 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
418 lock_icon_.reset([rb.GetNSImageNamed(IDR_LOCK) retain]);
419 }
420 SetImage(lock_icon_);
421 break;
422 case WARNING:
423 if (!warning_icon_.get()) {
424 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
425 warning_icon_.reset([rb.GetNSImageNamed(IDR_WARNING) retain]);
426 }
427 SetImage(warning_icon_);
353 break; 428 break;
354 default: 429 default:
355 NOTREACHED(); 430 NOTREACHED();
356 break; 431 break;
357 } 432 }
358 [field_ resetFieldEditorFrameIfNeeded];
359 } 433 }
434
435
436 bool LocationBarViewMac::SecurityImageView::OnMousePressed() {
437 TabContents* tab = BrowserList::GetLastActive()->GetSelectedTabContents();
438 NavigationEntry* nav_entry = tab->controller().GetActiveEntry();
439 if (!nav_entry) {
440 NOTREACHED();
441 return true;
442 }
443 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true);
444 return true;
445 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/location_bar_view_mac.h ('k') | skia/ext/skia_utils_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698