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

Side by Side Diff: chrome/browser/ui/panels/panel_window_controller_cocoa.mm

Issue 10066032: Enable user resizing for docked Panels (GTK and Mac). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 8 years, 8 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 | « chrome/browser/ui/panels/panel_strip.h ('k') | 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 // 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 #include "chrome/browser/ui/panels/panel_window_controller_cocoa.h" 5 #include "chrome/browser/ui/panels/panel_window_controller_cocoa.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 return self; 166 return self;
167 } 167 }
168 168
169 - (BOOL)acceptsFirstMouse:(NSEvent*)event { 169 - (BOOL)acceptsFirstMouse:(NSEvent*)event {
170 return YES; 170 return YES;
171 } 171 }
172 172
173 // |pointInWindow| is in window coordinates. 173 // |pointInWindow| is in window coordinates.
174 - (panel::ResizingSides)edgeHitTest:(NSPoint)pointInWindow { 174 - (panel::ResizingSides)edgeHitTest:(NSPoint)pointInWindow {
175 DCHECK(panel_->CanResizeByMouse()); 175 panel::Resizability resizability = panel_->CanResizeByMouse();
176 DCHECK_NE(panel::NOT_RESIZABLE, resizability);
176 177
177 NSPoint point = [self convertPoint:pointInWindow fromView:nil]; 178 NSPoint point = [self convertPoint:pointInWindow fromView:nil];
178 BOOL flipped = [self isFlipped]; 179 BOOL flipped = [self isFlipped];
179 if (NSMouseInRect(point, leftCursorRect_, flipped)) 180 if (NSMouseInRect(point, leftCursorRect_, flipped))
180 return panel::RESIZE_LEFT; 181 return panel::RESIZE_LEFT;
181 if (NSMouseInRect(point, rightCursorRect_, flipped)) 182 if (NSMouseInRect(point, rightCursorRect_, flipped))
182 return panel::RESIZE_RIGHT; 183 return panel::RESIZE_RIGHT;
183 if (NSMouseInRect(point, topCursorRect_, flipped)) 184 if (NSMouseInRect(point, topCursorRect_, flipped))
184 return panel::RESIZE_TOP; 185 return panel::RESIZE_TOP;
185 if (NSMouseInRect(point, bottomCursorRect_, flipped))
186 return panel::RESIZE_BOTTOM;
187 if (NSMouseInRect(point, topLeftCursorRect_, flipped)) 186 if (NSMouseInRect(point, topLeftCursorRect_, flipped))
188 return panel::RESIZE_TOP_LEFT; 187 return panel::RESIZE_TOP_LEFT;
189 if (NSMouseInRect(point, topRightCursorRect_, flipped)) 188 if (NSMouseInRect(point, topRightCursorRect_, flipped))
190 return panel::RESIZE_TOP_RIGHT; 189 return panel::RESIZE_TOP_RIGHT;
191 if (NSMouseInRect(point, bottomLeftCursorRect_, flipped)) 190
192 return panel::RESIZE_BOTTOM_LEFT; 191 // Bottom edge is not always resizable.
193 if (NSMouseInRect(point, bottomRightCursorRect_, flipped)) 192 if (panel::RESIZABLE_ALL_SIDES == resizability) {
194 return panel::RESIZE_BOTTOM_RIGHT; 193 if (NSMouseInRect(point, bottomCursorRect_, flipped))
194 return panel::RESIZE_BOTTOM;
195 if (NSMouseInRect(point, bottomLeftCursorRect_, flipped))
196 return panel::RESIZE_BOTTOM_LEFT;
197 if (NSMouseInRect(point, bottomRightCursorRect_, flipped))
198 return panel::RESIZE_BOTTOM_RIGHT;
199 }
195 200
196 return panel::RESIZE_NONE; 201 return panel::RESIZE_NONE;
197 } 202 }
198 203
199 // NSWindow uses this method to figure out if this view is under the mouse 204 // NSWindow uses this method to figure out if this view is under the mouse
200 // and hence the one to handle the incoming mouse event. 205 // and hence the one to handle the incoming mouse event.
201 // Since this view covers the whole panel, it is asked first. 206 // Since this view covers the whole panel, it is asked first.
202 // See if this is the mouse event we are interested in (in the resize areas) 207 // See if this is the mouse event we are interested in (in the resize areas)
203 // and return 'nil' to let NSWindow find another candidate otherwise. 208 // and return 'nil' to let NSWindow find another candidate otherwise.
204 // |point| is in coordinate system of the parent view. 209 // |point| is in coordinate system of the parent view.
205 - (NSView*)hitTest:(NSPoint)point { 210 - (NSView*)hitTest:(NSPoint)point {
206 // If panel is not resizable, let the mouse events fall through. 211 // If panel is not resizable, let the mouse events fall through.
207 if (!panel_->CanResizeByMouse()) 212 if (panel::NOT_RESIZABLE == panel_->CanResizeByMouse())
208 return nil; 213 return nil;
209 214
210 NSPoint pointInWindow = [[self superview] convertPoint:point toView:nil]; 215 NSPoint pointInWindow = [[self superview] convertPoint:point toView:nil];
211 return [self edgeHitTest:pointInWindow] == panel::RESIZE_NONE ? nil : self; 216 return [self edgeHitTest:pointInWindow] == panel::RESIZE_NONE ? nil : self;
212 } 217 }
213 218
214 - (void)mouseDown:(NSEvent*)event { 219 - (void)mouseDown:(NSEvent*)event {
215 // If the panel is not resizable, hitTest should have failed and no mouse 220 // If the panel is not resizable, hitTest should have failed and no mouse
216 // events should have came here. 221 // events should have came here.
217 DCHECK(panel_->CanResizeByMouse()); 222 DCHECK_NE(panel::NOT_RESIZABLE, panel_->CanResizeByMouse());
218 [self prepareForDrag:event]; 223 [self prepareForDrag:event];
219 } 224 }
220 225
221 - (void)mouseUp:(NSEvent*)event { 226 - (void)mouseUp:(NSEvent*)event {
222 // The mouseUp while in drag should be processed by nested message loop 227 // The mouseUp while in drag should be processed by nested message loop
223 // in mouseDragged: method. 228 // in mouseDragged: method.
224 DCHECK(dragState_ != PANEL_DRAG_IN_PROGRESS); 229 DCHECK(dragState_ != PANEL_DRAG_IN_PROGRESS);
225 // Cleanup in case the actual drag was not started (because of threshold). 230 // Cleanup in case the actual drag was not started (because of threshold).
226 [self cleanupAfterDrag]; 231 [self cleanupAfterDrag];
227 } 232 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 panel_->manager()->ResizeByMouse( 363 panel_->manager()->ResizeByMouse(
359 cocoa_utils::ConvertPointFromCocoaCoordinates(mouseLocationScreen)); 364 cocoa_utils::ConvertPointFromCocoaCoordinates(mouseLocationScreen));
360 } 365 }
361 366
362 - (void)endResize:(BOOL)cancelled { 367 - (void)endResize:(BOOL)cancelled {
363 DCHECK(dragState_ == PANEL_DRAG_IN_PROGRESS); 368 DCHECK(dragState_ == PANEL_DRAG_IN_PROGRESS);
364 panel_->manager()->EndResizingByMouse(cancelled); 369 panel_->manager()->EndResizingByMouse(cancelled);
365 } 370 }
366 371
367 - (void)resetCursorRects { 372 - (void)resetCursorRects {
368 if(!panel_->CanResizeByMouse()) 373 panel::Resizability resizability = panel_->CanResizeByMouse();
374 if (panel::NOT_RESIZABLE == resizability)
369 return; 375 return;
370 376
371 NSRect bounds = [self bounds]; 377 NSRect bounds = [self bounds];
372 378
373 // Left vertical edge. 379 // Left vertical edge.
374 leftCursorRect_ = NSMakeRect(NSMinX(bounds), 380 leftCursorRect_ = NSMakeRect(NSMinX(bounds),
375 NSMinY(bounds) + kWidthOfMouseResizeArea, 381 NSMinY(bounds) + kWidthOfMouseResizeArea,
376 kWidthOfMouseResizeArea, 382 kWidthOfMouseResizeArea,
377 NSHeight(bounds) - 2 * kWidthOfMouseResizeArea); 383 NSHeight(bounds) - 2 * kWidthOfMouseResizeArea);
378 [self addCursorRect:leftCursorRect_ cursor:eastWestCursor_]; 384 [self addCursorRect:leftCursorRect_ cursor:eastWestCursor_];
379 385
380 // Right vertical edge. 386 // Right vertical edge.
381 rightCursorRect_ = leftCursorRect_; 387 rightCursorRect_ = leftCursorRect_;
382 rightCursorRect_.origin.x = NSMaxX(bounds) - kWidthOfMouseResizeArea; 388 rightCursorRect_.origin.x = NSMaxX(bounds) - kWidthOfMouseResizeArea;
383 [self addCursorRect:rightCursorRect_ cursor:eastWestCursor_]; 389 [self addCursorRect:rightCursorRect_ cursor:eastWestCursor_];
384 390
385 // Top horizontal edge. 391 // Top horizontal edge.
386 topCursorRect_ = NSMakeRect(NSMinX(bounds) + kWidthOfMouseResizeArea, 392 topCursorRect_ = NSMakeRect(NSMinX(bounds) + kWidthOfMouseResizeArea,
387 NSMaxY(bounds) - kWidthOfMouseResizeArea, 393 NSMaxY(bounds) - kWidthOfMouseResizeArea,
388 NSWidth(bounds) - 2 * kWidthOfMouseResizeArea, 394 NSWidth(bounds) - 2 * kWidthOfMouseResizeArea,
389 kWidthOfMouseResizeArea); 395 kWidthOfMouseResizeArea);
390 [self addCursorRect:topCursorRect_ cursor:northSouthCursor_]; 396 [self addCursorRect:topCursorRect_ cursor:northSouthCursor_];
391 397
392 // Bottom horizontal edge.
393 bottomCursorRect_ = topCursorRect_;
394 bottomCursorRect_.origin.y = NSMinY(bounds);
395 [self addCursorRect:bottomCursorRect_ cursor:northSouthCursor_];
396
397 // Top left corner. 398 // Top left corner.
398 topLeftCursorRect_ = NSMakeRect(NSMinX(bounds), 399 topLeftCursorRect_ = NSMakeRect(NSMinX(bounds),
399 NSMaxY(bounds) - kWidthOfMouseResizeArea, 400 NSMaxY(bounds) - kWidthOfMouseResizeArea,
400 kWidthOfMouseResizeArea, 401 kWidthOfMouseResizeArea,
401 NSMaxY(bounds)); 402 NSMaxY(bounds));
402 [self addCursorRect:topLeftCursorRect_ cursor:northWestSouthEastCursor_]; 403 [self addCursorRect:topLeftCursorRect_ cursor:northWestSouthEastCursor_];
403 404
404 // Top right corner. 405 // Top right corner.
405 topRightCursorRect_ = topLeftCursorRect_; 406 topRightCursorRect_ = topLeftCursorRect_;
406 topRightCursorRect_.origin.x = NSMaxX(bounds) - kWidthOfMouseResizeArea; 407 topRightCursorRect_.origin.x = NSMaxX(bounds) - kWidthOfMouseResizeArea;
407 [self addCursorRect:topRightCursorRect_ cursor:northEastSouthWestCursor_]; 408 [self addCursorRect:topRightCursorRect_ cursor:northEastSouthWestCursor_];
408 409
410 // Bottom edge is not always resizable.
411 if (panel::RESIZABLE_ALL_SIDES_EXCEPT_BOTTOM == resizability)
412 return;
413
414 // Bottom horizontal edge.
415 bottomCursorRect_ = topCursorRect_;
416 bottomCursorRect_.origin.y = NSMinY(bounds);
417 [self addCursorRect:bottomCursorRect_ cursor:northSouthCursor_];
418
409 // Bottom right corner. 419 // Bottom right corner.
410 bottomRightCursorRect_ = topRightCursorRect_; 420 bottomRightCursorRect_ = topRightCursorRect_;
411 bottomRightCursorRect_.origin.y = NSMinY(bounds); 421 bottomRightCursorRect_.origin.y = NSMinY(bounds);
412 [self addCursorRect:bottomRightCursorRect_ cursor:northWestSouthEastCursor_]; 422 [self addCursorRect:bottomRightCursorRect_ cursor:northWestSouthEastCursor_];
413 423
414 // Bottom left corner. 424 // Bottom left corner.
415 bottomLeftCursorRect_ = bottomRightCursorRect_; 425 bottomLeftCursorRect_ = bottomRightCursorRect_;
416 bottomLeftCursorRect_.origin.x = NSMinX(bounds); 426 bottomLeftCursorRect_.origin.x = NSMinX(bounds);
417 [self addCursorRect:bottomLeftCursorRect_ cursor:northEastSouthWestCursor_]; 427 [self addCursorRect:bottomLeftCursorRect_ cursor:northEastSouthWestCursor_];
418 } 428 }
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 if (![self isWindowLoaded]) 1084 if (![self isWindowLoaded])
1075 return; 1085 return;
1076 [[self window] invalidateCursorRectsForView:overlayView_]; 1086 [[self window] invalidateCursorRectsForView:overlayView_];
1077 } 1087 }
1078 1088
1079 - (BOOL)isActivationByClickingTitlebarEnabled { 1089 - (BOOL)isActivationByClickingTitlebarEnabled {
1080 return !windowShim_->panel()->always_on_top(); 1090 return !windowShim_->panel()->always_on_top();
1081 } 1091 }
1082 1092
1083 @end 1093 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_strip.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698