| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "chrome/browser/ui/cocoa/bookmarks/bookmark_drag_drop_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_drag_drop_cocoa.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 18 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 18 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" | 19 #include "chrome/browser/bookmarks/bookmark_pasteboard_helper_mac.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" | 21 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" |
| 22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" | 22 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 [[NSGraphicsContext currentContext] graphicsPort]); | 62 [[NSGraphicsContext currentContext] graphicsPort]); |
| 63 CGContextBeginTransparencyLayerWithRect(context, NSRectToCGRect(frame), 0); | 63 CGContextBeginTransparencyLayerWithRect(context, NSRectToCGRect(frame), 0); |
| 64 { // Draw text clipped to frame. | 64 { // Draw text clipped to frame. |
| 65 gfx::ScopedNSGraphicsContextSaveGState scoped_state; | 65 gfx::ScopedNSGraphicsContextSaveGState scoped_state; |
| 66 [NSBezierPath clipRect:frame]; | 66 [NSBezierPath clipRect:frame]; |
| 67 [title drawAtPoint:frame.origin]; | 67 [title drawAtPoint:frame.origin]; |
| 68 } | 68 } |
| 69 | 69 |
| 70 NSColor* color = [NSColor blackColor]; | 70 NSColor* color = [NSColor blackColor]; |
| 71 NSColor* alpha_color = [color colorWithAlphaComponent:0.0]; | 71 NSColor* alpha_color = [color colorWithAlphaComponent:0.0]; |
| 72 scoped_nsobject<NSGradient> mask( | 72 base::scoped_nsobject<NSGradient> mask( |
| 73 [[NSGradient alloc] initWithStartingColor:color | 73 [[NSGradient alloc] initWithStartingColor:color endingColor:alpha_color]); |
| 74 endingColor:alpha_color]); | |
| 75 // Draw the gradient mask. | 74 // Draw the gradient mask. |
| 76 CGContextSetBlendMode(context, kCGBlendModeDestinationIn); | 75 CGContextSetBlendMode(context, kCGBlendModeDestinationIn); |
| 77 [mask drawFromPoint:NSMakePoint(NSMaxX(frame) - gradient_width, | 76 [mask drawFromPoint:NSMakePoint(NSMaxX(frame) - gradient_width, |
| 78 NSMinY(frame)) | 77 NSMinY(frame)) |
| 79 toPoint:NSMakePoint(NSMaxX(frame), | 78 toPoint:NSMakePoint(NSMaxX(frame), |
| 80 NSMinY(frame)) | 79 NSMinY(frame)) |
| 81 options:NSGradientDrawsBeforeStartingLocation]; | 80 options:NSGradientDrawsBeforeStartingLocation]; |
| 82 CGContextEndTransparencyLayer(context); | 81 CGContextEndTransparencyLayer(context); |
| 83 } | 82 } |
| 84 | 83 |
| 85 } // namespace | 84 } // namespace |
| 86 | 85 |
| 87 NSImage* DragImageForBookmark(NSImage* favicon, const string16& title) { | 86 NSImage* DragImageForBookmark(NSImage* favicon, const string16& title) { |
| 88 // If no favicon, use a default. | 87 // If no favicon, use a default. |
| 89 if (!favicon) { | 88 if (!favicon) { |
| 90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 91 favicon = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage(); | 90 favicon = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).ToNSImage(); |
| 92 } | 91 } |
| 93 | 92 |
| 94 // If no title, just use icon. | 93 // If no title, just use icon. |
| 95 if (title.empty()) | 94 if (title.empty()) |
| 96 return favicon; | 95 return favicon; |
| 97 NSString* ns_title = base::SysUTF16ToNSString(title); | 96 NSString* ns_title = base::SysUTF16ToNSString(title); |
| 98 | 97 |
| 99 // Set the look of the title. | 98 // Set the look of the title. |
| 100 NSDictionary* attrs = | 99 NSDictionary* attrs = |
| 101 [NSDictionary dictionaryWithObject:[NSFont systemFontOfSize: | 100 [NSDictionary dictionaryWithObject:[NSFont systemFontOfSize: |
| 102 [NSFont smallSystemFontSize]] | 101 [NSFont smallSystemFontSize]] |
| 103 forKey:NSFontAttributeName]; | 102 forKey:NSFontAttributeName]; |
| 104 scoped_nsobject<NSAttributedString> rich_title( | 103 base::scoped_nsobject<NSAttributedString> rich_title( |
| 105 [[NSAttributedString alloc] initWithString:ns_title | 104 [[NSAttributedString alloc] initWithString:ns_title attributes:attrs]); |
| 106 attributes:attrs]); | |
| 107 | 105 |
| 108 // Set up sizes and locations for rendering. | 106 // Set up sizes and locations for rendering. |
| 109 const CGFloat kIconMargin = 2.0; // Gap between icon and text. | 107 const CGFloat kIconMargin = 2.0; // Gap between icon and text. |
| 110 CGFloat text_left = [favicon size].width + kIconMargin; | 108 CGFloat text_left = [favicon size].width + kIconMargin; |
| 111 NSSize drag_image_size = [favicon size]; | 109 NSSize drag_image_size = [favicon size]; |
| 112 NSSize text_size = [rich_title size]; | 110 NSSize text_size = [rich_title size]; |
| 113 CGFloat max_text_width = bookmarks::kDefaultBookmarkWidth - text_left; | 111 CGFloat max_text_width = bookmarks::kDefaultBookmarkWidth - text_left; |
| 114 text_size.width = std::min(text_size.width, max_text_width); | 112 text_size.width = std::min(text_size.width, max_text_width); |
| 115 drag_image_size.width = text_left + text_size.width; | 113 drag_image_size.width = text_left + text_size.width; |
| 116 | 114 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 offset:NSZeroSize | 174 offset:NSZeroSize |
| 177 event:drag_event | 175 event:drag_event |
| 178 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] | 176 pasteboard:[NSPasteboard pasteboardWithName:NSDragPboard] |
| 179 source:nil | 177 source:nil |
| 180 slideBack:YES]; | 178 slideBack:YES]; |
| 181 | 179 |
| 182 base::MessageLoop::current()->SetNestableTasksAllowed(was_nested); | 180 base::MessageLoop::current()->SetNestableTasksAllowed(was_nested); |
| 183 } | 181 } |
| 184 | 182 |
| 185 } // namespace chrome | 183 } // namespace chrome |
| OLD | NEW |