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

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

Issue 3017055: Merge 54767 - [Mac] M6 Omnibox positioning changes.... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/472/src/
Patch Set: 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 | Annotate | Revision Log
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 #include <cmath>
6
5 #import "chrome/browser/cocoa/location_bar/page_action_decoration.h" 7 #import "chrome/browser/cocoa/location_bar/page_action_decoration.h"
6 8
7 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
8 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h" 10 #import "chrome/browser/cocoa/extensions/extension_action_context_menu.h"
9 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h" 11 #import "chrome/browser/cocoa/extensions/extension_popup_controller.h"
10 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" 12 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h"
11 #include "chrome/browser/extensions/extension_browser_event_router.h" 13 #include "chrome/browser/extensions/extension_browser_event_router.h"
12 #include "chrome/browser/extensions/extensions_service.h" 14 #include "chrome/browser/extensions/extensions_service.h"
13 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 16 #include "chrome/browser/tab_contents/tab_contents.h"
15 #include "chrome/common/extensions/extension_action.h" 17 #include "chrome/common/extensions/extension_action.h"
16 #include "chrome/common/extensions/extension_resource.h" 18 #include "chrome/common/extensions/extension_resource.h"
17 #include "skia/ext/skia_utils_mac.h" 19 #include "skia/ext/skia_utils_mac.h"
18 20
21 namespace {
22
23 // Distance to offset the bubble pointer from the bottom of the max
24 // icon area of the decoration. This makes the popup's upper border
25 // 2px away from the omnibox's lower border (matches omnibox popup
26 // upper border).
27 const CGFloat kBubblePointYOffset = 2.0;
28
29 } // namespace
30
19 PageActionDecoration::PageActionDecoration( 31 PageActionDecoration::PageActionDecoration(
20 LocationBarViewMac* owner, 32 LocationBarViewMac* owner,
21 Profile* profile, 33 Profile* profile,
22 ExtensionAction* page_action) 34 ExtensionAction* page_action)
23 : owner_(owner), 35 : owner_(owner),
24 profile_(profile), 36 profile_(profile),
25 page_action_(page_action), 37 page_action_(page_action),
26 tracker_(this), 38 tracker_(this),
27 current_tab_id_(-1), 39 current_tab_id_(-1),
28 preview_enabled_(false) { 40 preview_enabled_(false) {
(...skipping 15 matching lines...) Expand all
44 ImageLoadingTracker::DONT_CACHE); 56 ImageLoadingTracker::DONT_CACHE);
45 } 57 }
46 58
47 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, 59 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE,
48 Source<Profile>(profile_)); 60 Source<Profile>(profile_));
49 } 61 }
50 62
51 PageActionDecoration::~PageActionDecoration() { 63 PageActionDecoration::~PageActionDecoration() {
52 } 64 }
53 65
54 // Overridden from LocationBarImageView. Either notify listeners or show a 66 // Always |kPageActionIconMaxSize| wide. |ImageDecoration| draws the
55 // popup depending on the Page Action. 67 // image centered.
68 CGFloat PageActionDecoration::GetWidthForSpace(CGFloat width) {
69 return Extension::kPageActionIconMaxSize;
70 }
71
72 // Either notify listeners or show a popup depending on the Page
73 // Action.
56 bool PageActionDecoration::OnMousePressed(NSRect frame) { 74 bool PageActionDecoration::OnMousePressed(NSRect frame) {
57 if (current_tab_id_ < 0) { 75 if (current_tab_id_ < 0) {
58 NOTREACHED() << "No current tab."; 76 NOTREACHED() << "No current tab.";
59 // We don't want other code to try and handle this click. Returning true 77 // We don't want other code to try and handle this click. Returning true
60 // prevents this by indicating that we handled it. 78 // prevents this by indicating that we handled it.
61 return true; 79 return true;
62 } 80 }
63 81
64 if (page_action_->HasPopup(current_tab_id_)) { 82 if (page_action_->HasPopup(current_tab_id_)) {
65 // Anchor popup at the bottom center of the page action icon. 83 // Anchor popup at the bottom center of the page action icon.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 186
169 void PageActionDecoration::SetToolTip(std::string tooltip) { 187 void PageActionDecoration::SetToolTip(std::string tooltip) {
170 SetToolTip(tooltip.empty() ? nil : base::SysUTF8ToNSString(tooltip)); 188 SetToolTip(tooltip.empty() ? nil : base::SysUTF8ToNSString(tooltip));
171 } 189 }
172 190
173 NSString* PageActionDecoration::GetToolTip() { 191 NSString* PageActionDecoration::GetToolTip() {
174 return tooltip_.get(); 192 return tooltip_.get();
175 } 193 }
176 194
177 NSPoint PageActionDecoration::GetBubblePointInFrame(NSRect frame) { 195 NSPoint PageActionDecoration::GetBubblePointInFrame(NSRect frame) {
178 frame = GetDrawRectInFrame(frame); 196 // This is similar to |ImageDecoration::GetDrawRectInFrame()|,
179 return NSMakePoint(NSMidX(frame), NSMaxY(frame)); 197 // except that code centers the image, which can differ in size
198 // between actions. This centers the maximum image size, so the
199 // point will consistently be at the same y position. x position is
200 // easier (the middle of the centered image is the middle of the
201 // frame).
202 const CGFloat delta_height =
203 NSHeight(frame) - Extension::kPageActionIconMaxSize;
204 const CGFloat bottom_inset = std::ceil(delta_height / 2.0);
205
206 // Return a point just below the bottom of the maximal drawing area.
207 return NSMakePoint(NSMidX(frame),
208 NSMaxY(frame) - bottom_inset + kBubblePointYOffset);
180 } 209 }
181 210
182 NSMenu* PageActionDecoration::GetMenu() { 211 NSMenu* PageActionDecoration::GetMenu() {
183 if (!profile_) 212 if (!profile_)
184 return nil; 213 return nil;
185 ExtensionsService* service = profile_->GetExtensionsService(); 214 ExtensionsService* service = profile_->GetExtensionsService();
186 if (!service) 215 if (!service)
187 return nil; 216 return nil;
188 Extension* extension = service->GetExtensionById( 217 Extension* extension = service->GetExtensionById(
189 page_action_->extension_id(), false); 218 page_action_->extension_id(), false);
(...skipping 16 matching lines...) Expand all
206 if (popup && ![popup isClosing]) 235 if (popup && ![popup isClosing])
207 [popup close]; 236 [popup close];
208 237
209 break; 238 break;
210 } 239 }
211 default: 240 default:
212 NOTREACHED() << "Unexpected notification"; 241 NOTREACHED() << "Unexpected notification";
213 break; 242 break;
214 } 243 }
215 } 244 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/location_bar/page_action_decoration.h ('k') | chrome/browser/cocoa/location_bar/star_decoration.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698