OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/cocoa/bridged_content_view.h" | 5 #import "ui/views/cocoa/bridged_content_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "base/mac/mac_util.h" | 8 #import "base/mac/mac_util.h" |
9 #import "base/mac/scoped_nsobject.h" | 9 #import "base/mac/scoped_nsobject.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
11 #include "skia/ext/skia_utils_mac.h" | 11 #include "skia/ext/skia_utils_mac.h" |
12 #include "ui/base/cocoa/cocoa_base_utils.h" | 12 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 13 #include "ui/base/dragdrop/os_exchange_data_provider_mac.h" |
13 #include "ui/base/ime/input_method.h" | 14 #include "ui/base/ime/input_method.h" |
14 #include "ui/base/ime/text_input_client.h" | 15 #include "ui/base/ime/text_input_client.h" |
15 #include "ui/compositor/canvas_painter.h" | 16 #include "ui/compositor/canvas_painter.h" |
16 #import "ui/events/cocoa/cocoa_event_utils.h" | 17 #import "ui/events/cocoa/cocoa_event_utils.h" |
17 #include "ui/events/keycodes/dom/dom_code.h" | 18 #include "ui/events/keycodes/dom/dom_code.h" |
18 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" | 19 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
19 #include "ui/gfx/canvas_paint_mac.h" | 20 #include "ui/gfx/canvas_paint_mac.h" |
20 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
21 #import "ui/gfx/mac/coordinate_conversion.h" | 22 #import "ui/gfx/mac/coordinate_conversion.h" |
22 #include "ui/gfx/path.h" | 23 #include "ui/gfx/path.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 202 |
202 @end | 203 @end |
203 | 204 |
204 @implementation BridgedContentView | 205 @implementation BridgedContentView |
205 | 206 |
206 @synthesize hostedView = hostedView_; | 207 @synthesize hostedView = hostedView_; |
207 @synthesize textInputClient = textInputClient_; | 208 @synthesize textInputClient = textInputClient_; |
208 @synthesize drawMenuBackgroundForBlur = drawMenuBackgroundForBlur_; | 209 @synthesize drawMenuBackgroundForBlur = drawMenuBackgroundForBlur_; |
209 @synthesize mouseDownCanMoveWindow = mouseDownCanMoveWindow_; | 210 @synthesize mouseDownCanMoveWindow = mouseDownCanMoveWindow_; |
210 | 211 |
211 - (id)initWithView:(views::View*)viewToHost { | 212 - (id)initWithView:(views::View*)viewToHost |
| 213 dragDropManager:(views::CocoaDragDropManager*)dragDropManager { |
212 DCHECK(viewToHost); | 214 DCHECK(viewToHost); |
| 215 DCHECK(dragDropManager); |
213 gfx::Rect bounds = viewToHost->bounds(); | 216 gfx::Rect bounds = viewToHost->bounds(); |
214 // To keep things simple, assume the origin is (0, 0) until there exists a use | 217 // To keep things simple, assume the origin is (0, 0) until there exists a use |
215 // case for something other than that. | 218 // case for something other than that. |
216 DCHECK(bounds.origin().IsOrigin()); | 219 DCHECK(bounds.origin().IsOrigin()); |
217 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height()); | 220 NSRect initialFrame = NSMakeRect(0, 0, bounds.width(), bounds.height()); |
218 if ((self = [super initWithFrame:initialFrame])) { | 221 if ((self = [super initWithFrame:initialFrame])) { |
219 hostedView_ = viewToHost; | 222 hostedView_ = viewToHost; |
| 223 drag_drop_manager_ = dragDropManager; |
220 | 224 |
221 // Apple's documentation says that NSTrackingActiveAlways is incompatible | 225 // Apple's documentation says that NSTrackingActiveAlways is incompatible |
222 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp. | 226 // with NSTrackingCursorUpdate, so use NSTrackingActiveInActiveApp. |
223 cursorTrackingArea_.reset([[CrTrackingArea alloc] | 227 cursorTrackingArea_.reset([[CrTrackingArea alloc] |
224 initWithRect:NSZeroRect | 228 initWithRect:NSZeroRect |
225 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | | 229 options:NSTrackingMouseMoved | NSTrackingCursorUpdate | |
226 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect | 230 NSTrackingActiveInActiveApp | NSTrackingInVisibleRect |
227 owner:self | 231 owner:self |
228 userInfo:nil]); | 232 userInfo:nil]); |
229 [self addTrackingArea:cursorTrackingArea_.get()]; | 233 [self addTrackingArea:cursorTrackingArea_.get()]; |
230 | 234 |
231 // Get notified whenever Full Keyboard Access mode is changed. | 235 // Get notified whenever Full Keyboard Access mode is changed. |
232 [[NSDistributedNotificationCenter defaultCenter] | 236 [[NSDistributedNotificationCenter defaultCenter] |
233 addObserver:self | 237 addObserver:self |
234 selector:@selector(onFullKeyboardAccessModeChanged:) | 238 selector:@selector(onFullKeyboardAccessModeChanged:) |
235 name:kFullKeyboardAccessChangedNotification | 239 name:kFullKeyboardAccessChangedNotification |
236 object:nil]; | 240 object:nil]; |
237 | 241 |
238 // Initialize the focus manager with the correct keyboard accessibility | 242 // Initialize the focus manager with the correct keyboard accessibility |
239 // setting. | 243 // setting. |
240 [self updateFullKeyboardAccess]; | 244 [self updateFullKeyboardAccess]; |
241 } | 245 } |
| 246 |
| 247 [self registerForDraggedTypes:ui::OSExchangeDataProviderMac:: |
| 248 SupportedPasteboardTypes()]; |
| 249 |
242 return self; | 250 return self; |
243 } | 251 } |
244 | 252 |
245 - (void)clearView { | 253 - (void)clearView { |
246 textInputClient_ = nullptr; | 254 textInputClient_ = nullptr; |
247 hostedView_ = nullptr; | 255 hostedView_ = nullptr; |
248 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; | 256 [[NSDistributedNotificationCenter defaultCenter] removeObserver:self]; |
249 [cursorTrackingArea_.get() clearOwner]; | 257 [cursorTrackingArea_.get() clearOwner]; |
250 [self removeTrackingArea:cursorTrackingArea_.get()]; | 258 [self removeTrackingArea:cursorTrackingArea_.get()]; |
251 } | 259 } |
(...skipping 11 matching lines...) Expand all Loading... |
263 [self mouseEvent:theEvent]; | 271 [self mouseEvent:theEvent]; |
264 return; | 272 return; |
265 } | 273 } |
266 | 274 |
267 ui::MouseEvent event(theEvent); | 275 ui::MouseEvent event(theEvent); |
268 event.set_location( | 276 event.set_location( |
269 MovePointToWindow([theEvent locationInWindow], source, target)); | 277 MovePointToWindow([theEvent locationInWindow], source, target)); |
270 hostedView_->GetWidget()->OnMouseEvent(&event); | 278 hostedView_->GetWidget()->OnMouseEvent(&event); |
271 } | 279 } |
272 | 280 |
| 281 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { |
| 282 return drag_drop_manager_->DraggingOver(sender); |
| 283 } |
| 284 |
| 285 - (NSDragOperation)draggingUpdated:(id)sender { |
| 286 return drag_drop_manager_->DraggingOver(sender); |
| 287 } |
| 288 |
| 289 - (void)draggingEnded:(id)sender { |
| 290 drag_drop_manager_->EndDrag(); |
| 291 } |
| 292 |
| 293 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
| 294 return drag_drop_manager_->OnDrop(sender) != NSDragOperationNone; |
| 295 } |
| 296 |
273 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { | 297 - (void)updateTooltipIfRequiredAt:(const gfx::Point&)locationInContent { |
274 DCHECK(hostedView_); | 298 DCHECK(hostedView_); |
275 base::string16 newTooltipText; | 299 base::string16 newTooltipText; |
276 | 300 |
277 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); | 301 views::View* view = hostedView_->GetTooltipHandlerForPoint(locationInContent); |
278 if (view) { | 302 if (view) { |
279 gfx::Point viewPoint = locationInContent; | 303 gfx::Point viewPoint = locationInContent; |
280 views::View::ConvertPointToTarget(hostedView_, view, &viewPoint); | 304 views::View::ConvertPointToTarget(hostedView_, view, &viewPoint); |
281 if (!view->GetTooltipText(viewPoint, &newTooltipText)) | 305 if (!view->GetTooltipText(viewPoint, &newTooltipText)) |
282 DCHECK(newTooltipText.empty()); | 306 DCHECK(newTooltipText.empty()); |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 } | 1010 } |
987 | 1011 |
988 return [super accessibilityAttributeValue:attribute]; | 1012 return [super accessibilityAttributeValue:attribute]; |
989 } | 1013 } |
990 | 1014 |
991 - (id)accessibilityHitTest:(NSPoint)point { | 1015 - (id)accessibilityHitTest:(NSPoint)point { |
992 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 1016 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
993 } | 1017 } |
994 | 1018 |
995 @end | 1019 @end |
OLD | NEW |