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/image_utils.h" | |
11 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" | 10 #import "chrome/browser/cocoa/location_bar/location_bar_view_mac.h" |
12 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
13 #import "third_party/mozilla/NSPasteboard+Utils.h" | 12 #import "third_party/mozilla/NSPasteboard+Utils.h" |
14 | 13 |
15 LocationIconDecoration::LocationIconDecoration(LocationBarViewMac* owner) | 14 LocationIconDecoration::LocationIconDecoration(LocationBarViewMac* owner) |
16 : owner_(owner) { | 15 : owner_(owner) { |
17 } | 16 } |
18 LocationIconDecoration::~LocationIconDecoration() { | 17 LocationIconDecoration::~LocationIconDecoration() { |
19 } | 18 } |
20 | 19 |
21 NSImage* LocationIconDecoration::GetImage() { | |
22 return image_; | |
23 } | |
24 | |
25 void LocationIconDecoration::SetImage(NSImage* image) { | |
26 image_.reset([image retain]); | |
27 } | |
28 | |
29 CGFloat LocationIconDecoration::GetWidthForSpace(CGFloat width) { | |
30 NSImage* image = GetImage(); | |
31 if (image) { | |
32 const CGFloat image_width = [image size].width; | |
33 if (image_width >= width) | |
34 return image_width; | |
35 } | |
36 return kOmittedWidth; | |
37 } | |
38 | |
39 void LocationIconDecoration::DrawInFrame(NSRect frame, NSView* control_view) { | |
40 NSImage* image = GetImage(); | |
41 const CGFloat delta_height = NSHeight(frame) - [image size].height; | |
42 const CGFloat y_inset = std::floor(delta_height / 2.0); | |
43 [image drawInRect:NSInsetRect(frame, 0.0, y_inset) | |
44 fromRect:NSZeroRect // Entire image | |
45 operation:NSCompositeSourceOver | |
46 fraction:1.0 | |
47 neverFlipped:YES]; | |
48 } | |
49 | |
50 bool LocationIconDecoration::IsDraggable() { | 20 bool LocationIconDecoration::IsDraggable() { |
51 // Without a tab it will be impossible to get the information needed | 21 // Without a tab it will be impossible to get the information needed |
52 // to perform a drag. | 22 // to perform a drag. |
53 if (!owner_->GetTabContents()) | 23 if (!owner_->GetTabContents()) |
54 return false; | 24 return false; |
55 | 25 |
56 // Do not drag if the user has been editing the location bar, or the | 26 // Do not drag if the user has been editing the location bar, or the |
57 // location bar is at the NTP. | 27 // location bar is at the NTP. |
58 if (owner_->location_entry()->IsEditingOrEmpty()) | 28 if (owner_->location_entry()->IsEditingOrEmpty()) |
59 return false; | 29 return false; |
(...skipping 23 matching lines...) Expand all Loading... |
83 | 53 |
84 TabContents* tab = owner_->GetTabContents(); | 54 TabContents* tab = owner_->GetTabContents(); |
85 NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); | 55 NavigationEntry* nav_entry = tab->controller().GetActiveEntry(); |
86 if (!nav_entry) { | 56 if (!nav_entry) { |
87 NOTREACHED(); | 57 NOTREACHED(); |
88 return true; | 58 return true; |
89 } | 59 } |
90 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); | 60 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); |
91 return true; | 61 return true; |
92 } | 62 } |
OLD | NEW |