OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" | 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/memory/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #include "chrome/browser/bookmarks/bookmark_model.h" | 11 #include "chrome/browser/bookmarks/bookmark_model.h" |
12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" | 12 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_window.h" |
13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" | 13 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button_cell.h" |
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
15 #import "chrome/browser/ui/cocoa/view_id_util.h" | 15 #import "chrome/browser/ui/cocoa/view_id_util.h" |
16 #include "content/public/browser/user_metrics.h" | 16 #include "content/public/browser/user_metrics.h" |
17 | 17 |
18 using content::UserMetricsAction; | 18 using content::UserMetricsAction; |
19 | 19 |
20 // The opacity of the bookmark button drag image. | 20 // The opacity of the bookmark button drag image. |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 408 |
409 | 409 |
410 - (NSImage*)dragImage { | 410 - (NSImage*)dragImage { |
411 NSRect bounds = [self bounds]; | 411 NSRect bounds = [self bounds]; |
412 | 412 |
413 // Grab the image from the screen and put it in an |NSImage|. We can't use | 413 // Grab the image from the screen and put it in an |NSImage|. We can't use |
414 // this directly since we need to clip it and set its opacity. This won't work | 414 // this directly since we need to clip it and set its opacity. This won't work |
415 // if the source view is clipped. Fortunately, we don't display clipped | 415 // if the source view is clipped. Fortunately, we don't display clipped |
416 // bookmark buttons. | 416 // bookmark buttons. |
417 [self lockFocus]; | 417 [self lockFocus]; |
418 scoped_nsobject<NSBitmapImageRep> | 418 base::scoped_nsobject<NSBitmapImageRep> bitmap( |
419 bitmap([[NSBitmapImageRep alloc] initWithFocusedViewRect:bounds]); | 419 [[NSBitmapImageRep alloc] initWithFocusedViewRect:bounds]); |
420 [self unlockFocus]; | 420 [self unlockFocus]; |
421 scoped_nsobject<NSImage> image([[NSImage alloc] initWithSize:[bitmap size]]); | 421 base::scoped_nsobject<NSImage> image( |
| 422 [[NSImage alloc] initWithSize:[bitmap size]]); |
422 [image addRepresentation:bitmap]; | 423 [image addRepresentation:bitmap]; |
423 | 424 |
424 // Make an autoreleased |NSImage|, which will be returned, and draw into it. | 425 // Make an autoreleased |NSImage|, which will be returned, and draw into it. |
425 // By default, the |NSImage| will be completely transparent. | 426 // By default, the |NSImage| will be completely transparent. |
426 NSImage* dragImage = | 427 NSImage* dragImage = |
427 [[[NSImage alloc] initWithSize:[bitmap size]] autorelease]; | 428 [[[NSImage alloc] initWithSize:[bitmap size]] autorelease]; |
428 [dragImage lockFocus]; | 429 [dragImage lockFocus]; |
429 | 430 |
430 // Draw the image with the appropriate opacity, clipping it tightly. | 431 // Draw the image with the appropriate opacity, clipping it tightly. |
431 GradientButtonCell* cell = static_cast<GradientButtonCell*>([self cell]); | 432 GradientButtonCell* cell = static_cast<GradientButtonCell*>([self cell]); |
432 DCHECK([cell isKindOfClass:[GradientButtonCell class]]); | 433 DCHECK([cell isKindOfClass:[GradientButtonCell class]]); |
433 [[cell clipPathForFrame:bounds inView:self] setClip]; | 434 [[cell clipPathForFrame:bounds inView:self] setClip]; |
434 [image drawAtPoint:NSMakePoint(0, 0) | 435 [image drawAtPoint:NSMakePoint(0, 0) |
435 fromRect:NSMakeRect(0, 0, NSWidth(bounds), NSHeight(bounds)) | 436 fromRect:NSMakeRect(0, 0, NSWidth(bounds), NSHeight(bounds)) |
436 operation:NSCompositeSourceOver | 437 operation:NSCompositeSourceOver |
437 fraction:kDragImageOpacity]; | 438 fraction:kDragImageOpacity]; |
438 | 439 |
439 [dragImage unlockFocus]; | 440 [dragImage unlockFocus]; |
440 return dragImage; | 441 return dragImage; |
441 } | 442 } |
442 | 443 |
443 @end // @implementation BookmarkButton(Private) | 444 @end // @implementation BookmarkButton(Private) |
OLD | NEW |