Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: third_party/mozilla/include/ToolTip.mm

Issue 125166: Clicking on any tile in the NTP would hide the window. Surprising!... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK ***** 2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * 4 *
5 * The contents of this file are subject to the Mozilla Public License Version 5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with 6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at 7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/ 8 * http://www.mozilla.org/MPL/
9 * 9 *
10 * Software distributed under the License is distributed on an "AS IS" basis, 10 * Software distributed under the License is distributed on an "AS IS" basis,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 { 58 {
59 // the ref from -alloc is balanced by the -release in dealloc 59 // the ref from -alloc is balanced by the -release in dealloc
60 mTooltipWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0.0, 0.0, kMaxTextFieldWidth, 0.0) 60 mTooltipWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0.0, 0.0, kMaxTextFieldWidth, 0.0)
61 styleMask:NSBorderlessWindowMask 61 styleMask:NSBorderlessWindowMask
62 backing:NSBackingStoreBuffered 62 backing:NSBackingStoreBuffered
63 defer:YES]; 63 defer:YES];
64 64
65 // we don't want closing the window to release it, because we aren't always in control 65 // we don't want closing the window to release it, because we aren't always in control
66 // of the close (AppKit may do it on quit). 66 // of the close (AppKit may do it on quit).
67 [mTooltipWindow setReleasedWhenClosed:NO]; 67 [mTooltipWindow setReleasedWhenClosed:NO];
68 68
69 // Create a textfield as the content of our new window. 69 // Create a textfield as the content of our new window.
70 // Field occupies all but the top 2 and bottom 2 pixels of the panel (bug 14 9635) 70 // Field occupies all but the top 2 and bottom 2 pixels of the panel (bug 14 9635)
71 mTextView = [[NSTextView alloc] initWithFrame:NSMakeRect(0.0, kBorderPadding , kMaxTextFieldWidth, 0.0)]; 71 mTextView = [[NSTextView alloc] initWithFrame:NSMakeRect(0.0, kBorderPadding , kMaxTextFieldWidth, 0.0)];
72 [[mTooltipWindow contentView] addSubview:mTextView]; 72 [[mTooltipWindow contentView] addSubview:mTextView];
73 [mTextView release]; // window holds ref 73 [mTextView release]; // window holds ref
74 74
75 // set up the panel 75 // set up the panel
76 [mTooltipWindow setHasShadow:YES]; 76 [mTooltipWindow setHasShadow:YES];
77 [mTooltipWindow setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green :1.0 blue:0.81 alpha:1.0]]; 77 [mTooltipWindow setBackgroundColor:[NSColor colorWithCalibratedRed:1.0 green :1.0 blue:0.81 alpha:1.0]];
78 78
79 79
80 // set up the text view 80 // set up the text view
81 [mTextView setDrawsBackground:NO]; 81 [mTextView setDrawsBackground:NO];
82 [mTextView setEditable:NO]; 82 [mTextView setEditable:NO];
83 [mTextView setSelectable:NO]; 83 [mTextView setSelectable:NO];
84 [mTextView setFont:[NSFont toolTipsFontOfSize:[NSFont smallSystemFontSize]]] ; 84 [mTextView setFont:[NSFont toolTipsFontOfSize:[NSFont smallSystemFontSize]]] ;
85 [mTextView setMinSize:NSMakeSize(0.0, 0.0)]; 85 [mTextView setMinSize:NSMakeSize(0.0, 0.0)];
86 [mTextView setHorizontallyResizable:YES]; 86 [mTextView setHorizontallyResizable:YES];
87 [mTextView setVerticallyResizable:YES]; 87 [mTextView setVerticallyResizable:YES];
88 } 88 }
89 return self; 89 return self;
90 } 90 }
91 91
92 - (void)dealloc 92 - (void)dealloc
93 { 93 {
94 [self closeToolTip];
95
94 [[NSNotificationCenter defaultCenter] removeObserver:self]; 96 [[NSNotificationCenter defaultCenter] removeObserver:self];
95 97
96 [mTooltipWindow close]; // we set the window not to release on -close 98 [mTooltipWindow close]; // we set the window not to release on -close
97 [mTooltipWindow release]; 99 [mTooltipWindow release];
98 100
99 [super dealloc]; 101 [super dealloc];
100 } 102 }
101 103
102 - (void)showToolTipAtPoint:(NSPoint)windowPoint 104 - (void)showToolTipAtPoint:(NSPoint)windowPoint
103 withString:(NSString*)string 105 withString:(NSString*)string
(...skipping 26 matching lines...) Expand all
130 [mTextView setFrame:NSMakeRect(0, kBorderPadding, 0, 0)]; 132 [mTextView setFrame:NSMakeRect(0, kBorderPadding, 0, 0)];
131 133
132 // -sizeToFit sucks. For some reason it likes to wrap short words, so 134 // -sizeToFit sucks. For some reason it likes to wrap short words, so
133 // we measure the text by hand and set that as the min width. 135 // we measure the text by hand and set that as the min width.
134 NSSize stringSize = [string sizeWithAttributes:[NSDictionary dictionaryWithObj ect:[NSFont toolTipsFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttrib uteName]]; 136 NSSize stringSize = [string sizeWithAttributes:[NSDictionary dictionaryWithObj ect:[NSFont toolTipsFontOfSize:[NSFont smallSystemFontSize]] forKey:NSFontAttrib uteName]];
135 float textViewWidth = ceil(stringSize.width); 137 float textViewWidth = ceil(stringSize.width);
136 if (textViewWidth > kMaxTextFieldWidth) 138 if (textViewWidth > kMaxTextFieldWidth)
137 textViewWidth = kMaxTextFieldWidth; 139 textViewWidth = kMaxTextFieldWidth;
138 140
139 textViewWidth += 2.0 * 5.0; // magic numbers required to make the text not w rap. No, this isn't -textContainerInset. 141 textViewWidth += 2.0 * 5.0; // magic numbers required to make the text not w rap. No, this isn't -textContainerInset.
140 142
141 // set up the text view 143 // set up the text view
142 [mTextView setMaxSize:NSMakeSize(kMaxTextFieldWidth, screenSize.height - 2 * k BorderPadding)]; // do this here since we know screen size 144 [mTextView setMaxSize:NSMakeSize(kMaxTextFieldWidth, screenSize.height - 2 * k BorderPadding)]; // do this here since we know screen size
143 [mTextView setString:string]; // do this after setting max size, before settin g constrained frame size, 145 [mTextView setString:string]; // do this after setting max size, before settin g constrained frame size,
144 // reset to max width - it will not grow horizon tally when resizing, only vertically 146 // reset to max width - it will not grow horizon tally when resizing, only vertically
145 [mTextView setConstrainedFrameSize:NSMakeSize(kMaxTextFieldWidth, 0.0)]; 147 [mTextView setConstrainedFrameSize:NSMakeSize(kMaxTextFieldWidth, 0.0)];
146 // to avoid wrapping when we don't want it, set the min width 148 // to avoid wrapping when we don't want it, set the min width
147 [mTextView setMinSize:NSMakeSize(textViewWidth, 0.0)]; 149 [mTextView setMinSize:NSMakeSize(textViewWidth, 0.0)];
148 150
149 // finally, do the buggy sizeToFit 151 // finally, do the buggy sizeToFit
150 [mTextView sizeToFit]; 152 [mTextView sizeToFit];
151 // The first time we sizeToFit a text field on Leopard, it decides that 153 // The first time we sizeToFit a text field on Leopard, it decides that
152 // 0 would be a good height. We disagree, so make it try again. 154 // 0 would be a good height. We disagree, so make it try again.
153 NSRect textViewFrame = [mTextView frame]; 155 NSRect textViewFrame = [mTextView frame];
154 if (textViewFrame.size.height < 1.0) { 156 if (textViewFrame.size.height < 1.0) {
155 [mTextView sizeToFit]; 157 [mTextView sizeToFit];
156 textViewFrame = [mTextView frame]; 158 textViewFrame = [mTextView frame];
157 } 159 }
158 160
159 // set the origin back where its supposed to be 161 // set the origin back where its supposed to be
160 [mTextView setFrameOrigin:NSMakePoint(0, kBorderPadding)]; 162 [mTextView setFrameOrigin:NSMakePoint(0, kBorderPadding)];
161 163
162 // size the panel correctly, taking border into account 164 // size the panel correctly, taking border into account
163 NSSize textSize = textViewFrame.size; 165 NSSize textSize = textViewFrame.size;
164 textSize.height += kBorderPadding + kBorderPadding; 166 textSize.height += kBorderPadding + kBorderPadding;
165 [mTooltipWindow setContentSize:textSize]; 167 [mTooltipWindow setContentSize:textSize];
166 168
167 // We try to put the top left point right below the cursor. If that doesn't fi t 169 // We try to put the top left point right below the cursor. If that doesn't fi t
168 // on screen, put the bottom left point above the cursor. 170 // on screen, put the bottom left point above the cursor.
169 if (point.y - kVOffset - textSize.height > NSMinY(screenFrame)) { 171 if (point.y - kVOffset - textSize.height > NSMinY(screenFrame)) {
170 point.y -= kVOffset; 172 point.y -= kVOffset;
171 [mTooltipWindow setFrameTopLeftPoint:point]; 173 [mTooltipWindow setFrameTopLeftPoint:point];
172 } 174 }
173 else { 175 else {
174 point.y += kVOffset / 2.5; 176 point.y += kVOffset / 2.5;
175 [mTooltipWindow setFrameOrigin:point]; 177 [mTooltipWindow setFrameOrigin:point];
176 } 178 }
177 179
178 // if it doesn't fit on screen horizontally, adjust so that it does 180 // if it doesn't fit on screen horizontally, adjust so that it does
179 float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mTooltipWindow frame]); 181 float amountOffScreenX = NSMaxX(screenFrame) - NSMaxX([mTooltipWindow frame]);
180 if (amountOffScreenX < 0) { 182 if (amountOffScreenX < 0) {
181 NSRect movedFrame = [mTooltipWindow frame]; 183 NSRect movedFrame = [mTooltipWindow frame];
182 movedFrame.origin.x += amountOffScreenX; 184 movedFrame.origin.x += amountOffScreenX;
183 [mTooltipWindow setFrame:movedFrame display:NO]; 185 [mTooltipWindow setFrame:movedFrame display:NO];
184 } 186 }
185 187
186 // add as a child window 188 // add as a child window
187 [inWindow addChildWindow:mTooltipWindow ordered:NSWindowAbove]; 189 [inWindow addChildWindow:mTooltipWindow ordered:NSWindowAbove];
188 // show the panel 190 // show the panel
189 [mTooltipWindow orderFront:nil]; 191 [mTooltipWindow orderFront:nil];
190 } 192 }
191 193
192 - (void)closeToolTip 194 - (void)closeToolTip
193 { 195 {
194 // we can get -closeToolTip even if we didn't show it 196 // we can get -closeToolTip even if we didn't show it
195 if ([mTooltipWindow isVisible]) 197 if ([mTooltipWindow isVisible])
196 { 198 {
197 [[mTooltipWindow parentWindow] removeChildWindow:mTooltipWindow]; 199 [[mTooltipWindow parentWindow] removeChildWindow:mTooltipWindow];
198 [mTooltipWindow orderOut:nil]; 200 [mTooltipWindow orderOut:nil];
199 } 201 }
200 202
201 [[NSNotificationCenter defaultCenter] removeObserver:self]; 203 [[NSNotificationCenter defaultCenter] removeObserver:self];
202 } 204 }
203 205
204 - (void)parentWindowDidResignKey:(NSNotification*)inNotification 206 - (void)parentWindowDidResignKey:(NSNotification*)inNotification
205 { 207 {
206 [self closeToolTip]; 208 [self closeToolTip];
207 } 209 }
208 210
209 @end 211 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698