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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h" | 7 #import "chrome/browser/cocoa/location_bar/location_icon_decoration.h" |
8 | 8 |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" | 10 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" |
11 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
12 #import "third_party/mozilla/NSPasteboard+Utils.h" | 12 #import "third_party/mozilla/NSPasteboard+Utils.h" |
13 | 13 |
| 14 // The info-bubble point should look like it points to the point |
| 15 // between the star's lower tips. The popup should be where the |
| 16 // Omnibox popup ends up (2px below field). Determined via Pixie.app |
| 17 // magnification. |
| 18 const CGFloat kBubblePointYOffset = 2.0; |
| 19 |
14 LocationIconDecoration::LocationIconDecoration(LocationBarViewMac* owner) | 20 LocationIconDecoration::LocationIconDecoration(LocationBarViewMac* owner) |
15 : owner_(owner) { | 21 : owner_(owner) { |
16 } | 22 } |
17 LocationIconDecoration::~LocationIconDecoration() { | 23 LocationIconDecoration::~LocationIconDecoration() { |
18 } | 24 } |
19 | 25 |
20 bool LocationIconDecoration::IsDraggable() { | 26 bool LocationIconDecoration::IsDraggable() { |
21 // Without a tab it will be impossible to get the information needed | 27 // Without a tab it will be impossible to get the information needed |
22 // to perform a drag. | 28 // to perform a drag. |
23 if (!owner_->GetTabContents()) | 29 if (!owner_->GetTabContents()) |
(...skipping 14 matching lines...) Expand all Loading... |
38 NSString* url = base::SysUTF8ToNSString(tab->GetURL().spec()); | 44 NSString* url = base::SysUTF8ToNSString(tab->GetURL().spec()); |
39 NSString* title = base::SysUTF16ToNSString(tab->GetTitle()); | 45 NSString* title = base::SysUTF16ToNSString(tab->GetTitle()); |
40 | 46 |
41 NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; | 47 NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard]; |
42 [pboard declareURLPasteboardWithAdditionalTypes:[NSArray array] | 48 [pboard declareURLPasteboardWithAdditionalTypes:[NSArray array] |
43 owner:nil]; | 49 owner:nil]; |
44 [pboard setDataForURL:url title:title]; | 50 [pboard setDataForURL:url title:title]; |
45 return pboard; | 51 return pboard; |
46 } | 52 } |
47 | 53 |
| 54 NSPoint LocationIconDecoration::GetBubblePointInFrame(NSRect frame) { |
| 55 const NSRect draw_frame = GetDrawRectInFrame(frame); |
| 56 return NSMakePoint(NSMidX(draw_frame), |
| 57 NSMaxY(draw_frame) - kBubblePointYOffset); |
| 58 } |
| 59 |
48 bool LocationIconDecoration::OnMousePressed(NSRect frame) { | 60 bool LocationIconDecoration::OnMousePressed(NSRect frame) { |
49 // Do not show page info if the user has been editing the location | 61 // Do not show page info if the user has been editing the location |
50 // bar, or the location bar is at the NTP. | 62 // bar, or the location bar is at the NTP. |
51 if (owner_->location_entry()->IsEditingOrEmpty()) | 63 if (owner_->location_entry()->IsEditingOrEmpty()) |
52 return true; | 64 return true; |
53 | 65 |
54 TabContents* tab = owner_->GetTabContents(); | 66 TabContents* tab = owner_->GetTabContents(); |
55 NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); | 67 NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); |
56 if (!nav_entry) { | 68 if (!nav_entry) { |
57 NOTREACHED(); | 69 NOTREACHED(); |
58 return true; | 70 return true; |
59 } | 71 } |
60 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); | 72 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); |
61 return true; | 73 return true; |
62 } | 74 } |
OLD | NEW |