/
FaviconView.m
90 lines (71 loc) · 2.03 KB
/
FaviconView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// FaviconView.m
// StainlessClient
//
// Created by Danny Espinoza on 1/30/09.
// Copyright 2009 Mesa Dynamics, LLC. All rights reserved.
//
#import "FaviconView.h"
#import "StainlessTabView.h"
#import "StainlessController.h"
extern BOOL gPrivateMode;
extern BOOL gIconShelf;
@implementation FaviconView
- (id)initWithFrame:(NSRect)frame
{
if(self = [super initWithFrame:frame]) {
mouseDown = NO;
}
return self;
}
- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
{
return YES;
}
- (void)mouseDown:(NSEvent *)theEvent
{
mouseDown = YES;
}
- (void)mouseUp:(NSEvent *)theEvent
{
if(mouseDown) {
StainlessController* controller = (StainlessController*)[NSApp delegate];
StainlessTabView* tab = (StainlessTabView*) [self superview];
[controller switchTab:tab];
}
mouseDown = NO;
}
- (void)mouseDragged:(NSEvent *)theEvent
{
if(mouseDown) {
mouseDown = NO;
if(gPrivateMode)
return;
StainlessTabView* tab = (StainlessTabView*) [self superview];
NSString* urlString = [tab tabURL];
if(urlString && [urlString length]) {
NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[tab writeToPasteboard:pboard];
NSPoint framePosition = [self convertPoint:[theEvent locationInWindow] fromView:nil];
NSPoint dragPosition = [theEvent locationInWindow];
dragPosition.x -= framePosition.x;
dragPosition.y -= framePosition.y;
BOOL revealShelf = NO;
if(gIconShelf == NO) {
StainlessController* controller = (StainlessController*)[NSApp delegate];
[controller toggleIconShelf:self];
revealShelf = YES;
}
[[self window] dragImage:[self image] at:dragPosition offset:NSMakeSize(0.0, 0.0) event:theEvent pasteboard:pboard source:self slideBack:NO];
if(revealShelf)
[NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(hideIconShelf:) userInfo:nil repeats:NO];
}
}
}
// Callbacks
- (void)hideIconShelf:(id)sender
{
StainlessController* controller = (StainlessController*)[NSApp delegate];
[controller toggleIconShelf:self];
}
@end