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

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

Issue 3054040: [Mac] Adjust browser-action and content-setting popup points (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: Merge to LKGR. Created 10 years, 4 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/content_setting_decoration.h" 5 #import "chrome/browser/cocoa/location_bar/content_setting_decoration.h"
6 6
7 #include "app/resource_bundle.h" 7 #include "app/resource_bundle.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h" 10 #import "chrome/browser/cocoa/content_blocked_bubble_controller.h"
11 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" 11 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h"
12 #include "chrome/browser/content_setting_image_model.h" 12 #include "chrome/browser/content_setting_image_model.h"
13 #include "chrome/browser/content_setting_bubble_model.h" 13 #include "chrome/browser/content_setting_bubble_model.h"
14 #include "chrome/browser/pref_service.h" 14 #include "chrome/browser/pref_service.h"
15 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
16 #include "chrome/browser/tab_contents/tab_contents.h" 16 #include "chrome/browser/tab_contents/tab_contents.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
19 19
20 namespace {
21
22 // How far to offset up from the bottom of the view to get the top
23 // border of the popup 2px below the bottom of the Omnibox.
24 const CGFloat kPopupPointYOffset = 2.0;
25
26 } // namespace
27
20 ContentSettingDecoration::ContentSettingDecoration( 28 ContentSettingDecoration::ContentSettingDecoration(
21 ContentSettingsType settings_type, 29 ContentSettingsType settings_type,
22 LocationBarViewMac* owner, 30 LocationBarViewMac* owner,
23 Profile* profile) 31 Profile* profile)
24 : content_setting_image_model_( 32 : content_setting_image_model_(
25 ContentSettingImageModel::CreateContentSettingImageModel( 33 ContentSettingImageModel::CreateContentSettingImageModel(
26 settings_type)), 34 settings_type)),
27 owner_(owner), 35 owner_(owner),
28 profile_(profile) { 36 profile_(profile) {
29 } 37 }
30 38
31 ContentSettingDecoration::~ContentSettingDecoration() { 39 ContentSettingDecoration::~ContentSettingDecoration() {
32 } 40 }
33 41
34 void ContentSettingDecoration::UpdateFromTabContents( 42 void ContentSettingDecoration::UpdateFromTabContents(
35 const TabContents* tab_contents) { 43 const TabContents* tab_contents) {
36 content_setting_image_model_->UpdateFromTabContents(tab_contents); 44 content_setting_image_model_->UpdateFromTabContents(tab_contents);
37 SetVisible(content_setting_image_model_->is_visible()); 45 SetVisible(content_setting_image_model_->is_visible());
38 if (IsVisible()) { 46 if (IsVisible()) {
39 // TODO(thakis): We should use pdfs for these icons on OSX. 47 // TODO(thakis): We should use pdfs for these icons on OSX.
40 // http://crbug.com/35847 48 // http://crbug.com/35847
41 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 49 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
42 SetImage(rb.GetNSImageNamed(content_setting_image_model_->get_icon())); 50 SetImage(rb.GetNSImageNamed(content_setting_image_model_->get_icon()));
43 SetToolTip(base::SysUTF8ToNSString( 51 SetToolTip(base::SysUTF8ToNSString(
44 content_setting_image_model_->get_tooltip())); 52 content_setting_image_model_->get_tooltip()));
45 } 53 }
46 } 54 }
47 55
56 NSPoint ContentSettingDecoration::GetBubblePointInFrame(NSRect frame) {
57 const NSRect draw_frame = GetDrawRectInFrame(frame);
58 return NSMakePoint(NSMidX(draw_frame),
59 NSMaxY(draw_frame) - kPopupPointYOffset);
60 }
61
48 bool ContentSettingDecoration::OnMousePressed(NSRect frame) { 62 bool ContentSettingDecoration::OnMousePressed(NSRect frame) {
49 // Get host. This should be shared on linux/win/osx medium-term. 63 // Get host. This should be shared on linux/win/osx medium-term.
50 TabContents* tabContents = 64 TabContents* tabContents =
51 BrowserList::GetLastActive()->GetSelectedTabContents(); 65 BrowserList::GetLastActive()->GetSelectedTabContents();
52 if (!tabContents) 66 if (!tabContents)
53 return true; 67 return true;
54 68
55 GURL url = tabContents->GetURL(); 69 GURL url = tabContents->GetURL();
56 std::wstring displayHost; 70 std::wstring displayHost;
57 net::AppendFormattedHost( 71 net::AppendFormattedHost(
58 url, 72 url,
59 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), 73 UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)),
60 &displayHost, NULL, NULL); 74 &displayHost, NULL, NULL);
61 75
62 // Find point for bubble's arrow in screen coordinates. 76 // Find point for bubble's arrow in screen coordinates.
63 // TODO(shess): |owner_| is only being used to fetch |field|. 77 // TODO(shess): |owner_| is only being used to fetch |field|.
64 // Consider passing in |control_view|. 78 // Consider passing in |control_view|. Or refactoring to be
79 // consistent with other decorations (which don't currently bring up
80 // their bubble directly).
65 AutocompleteTextField* field = owner_->GetAutocompleteTextField(); 81 AutocompleteTextField* field = owner_->GetAutocompleteTextField();
66 frame = GetDrawRectInFrame(frame); 82 NSPoint anchor = GetBubblePointInFrame(frame);
67 NSPoint anchor = NSMakePoint(NSMidX(frame) + 1, NSMaxY(frame));
68 anchor = [field convertPoint:anchor toView:nil]; 83 anchor = [field convertPoint:anchor toView:nil];
69 anchor = [[field window] convertBaseToScreen:anchor]; 84 anchor = [[field window] convertBaseToScreen:anchor];
70 85
71 // Open bubble. 86 // Open bubble.
72 ContentSettingBubbleModel* model = 87 ContentSettingBubbleModel* model =
73 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 88 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
74 tabContents, profile_, 89 tabContents, profile_,
75 content_setting_image_model_->get_content_settings_type()); 90 content_setting_image_model_->get_content_settings_type());
76 [ContentBlockedBubbleController showForModel:model 91 [ContentBlockedBubbleController showForModel:model
77 parentWindow:[field window] 92 parentWindow:[field window]
78 anchoredAt:anchor]; 93 anchoredAt:anchor];
79 return true; 94 return true;
80 } 95 }
81 96
82 NSString* ContentSettingDecoration::GetToolTip() { 97 NSString* ContentSettingDecoration::GetToolTip() {
83 return tooltip_.get(); 98 return tooltip_.get();
84 } 99 }
85 100
86 void ContentSettingDecoration::SetToolTip(NSString* tooltip) { 101 void ContentSettingDecoration::SetToolTip(NSString* tooltip) {
87 tooltip_.reset([tooltip retain]); 102 tooltip_.reset([tooltip retain]);
88 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698