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

Side by Side Diff: ui/views/cocoa/bridged_native_widget.mm

Issue 891003004: MacViews: Implement SetCursor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20150129-MacViews-Bringup5
Patch Set: assign -> retain Created 5 years, 10 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
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.h ('k') | ui/views/cocoa/native_widget_mac_nswindow.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_native_widget.h" 5 #import "ui/views/cocoa/bridged_native_widget.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 197 }
198 DCHECK(window_visible_); 198 DCHECK(window_visible_);
199 } 199 }
200 200
201 void BridgedNativeWidget::AcquireCapture() { 201 void BridgedNativeWidget::AcquireCapture() {
202 DCHECK(!HasCapture()); 202 DCHECK(!HasCapture());
203 if (!window_visible_) 203 if (!window_visible_)
204 return; // Capture on hidden windows is disallowed. 204 return; // Capture on hidden windows is disallowed.
205 205
206 mouse_capture_.reset(new CocoaMouseCapture(this)); 206 mouse_capture_.reset(new CocoaMouseCapture(this));
207
208 // Initiating global event capture with addGlobalMonitorForEventsMatchingMask:
209 // will reset the mouse cursor to an arrow. Asking the window for an update
210 // here will restore what we want. However, it can sometimes cause the cursor
211 // to flicker, once, on the initial mouseDown.
212 // TOOD(tapted): Make this unnecessary by only asking for global mouse capture
213 // for the cases that need it (e.g. menus, but not drag and drop).
214 [window_ cursorUpdate:[NSApp currentEvent]];
207 } 215 }
208 216
209 void BridgedNativeWidget::ReleaseCapture() { 217 void BridgedNativeWidget::ReleaseCapture() {
210 mouse_capture_.reset(); 218 mouse_capture_.reset();
211 } 219 }
212 220
213 bool BridgedNativeWidget::HasCapture() { 221 bool BridgedNativeWidget::HasCapture() {
214 return mouse_capture_ && mouse_capture_->IsActive(); 222 return mouse_capture_ && mouse_capture_->IsActive();
215 } 223 }
216 224
217 void BridgedNativeWidget::SetNativeWindowProperty(const char* name, 225 void BridgedNativeWidget::SetNativeWindowProperty(const char* name,
218 void* value) { 226 void* value) {
219 NSString* key = [NSString stringWithUTF8String:name]; 227 NSString* key = [NSString stringWithUTF8String:name];
220 if (value) { 228 if (value) {
221 [GetWindowProperties() setObject:[NSValue valueWithPointer:value] 229 [GetWindowProperties() setObject:[NSValue valueWithPointer:value]
222 forKey:key]; 230 forKey:key];
223 } else { 231 } else {
224 [GetWindowProperties() removeObjectForKey:key]; 232 [GetWindowProperties() removeObjectForKey:key];
225 } 233 }
226 } 234 }
227 235
228 void* BridgedNativeWidget::GetNativeWindowProperty(const char* name) const { 236 void* BridgedNativeWidget::GetNativeWindowProperty(const char* name) const {
229 NSString* key = [NSString stringWithUTF8String:name]; 237 NSString* key = [NSString stringWithUTF8String:name];
230 return [[GetWindowProperties() objectForKey:key] pointerValue]; 238 return [[GetWindowProperties() objectForKey:key] pointerValue];
231 } 239 }
232 240
241 void BridgedNativeWidget::SetCursor(NSCursor* cursor) {
242 [window_delegate_ setCursor:cursor];
243 }
244
233 void BridgedNativeWidget::OnWindowWillClose() { 245 void BridgedNativeWidget::OnWindowWillClose() {
234 if (parent_) 246 if (parent_)
235 parent_->RemoveChildWindow(this); 247 parent_->RemoveChildWindow(this);
236 [window_ setDelegate:nil]; 248 [window_ setDelegate:nil];
237 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; 249 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_];
238 native_widget_mac_->OnWindowWillClose(); 250 native_widget_mac_->OnWindowWillClose();
239 } 251 }
240 252
241 void BridgedNativeWidget::OnFullscreenTransitionStart( 253 void BridgedNativeWidget::OnFullscreenTransitionStart(
242 bool target_fullscreen_state) { 254 bool target_fullscreen_state) {
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 window_, &kWindowPropertiesKey); 697 window_, &kWindowPropertiesKey);
686 if (!properties) { 698 if (!properties) {
687 properties = [NSMutableDictionary dictionary]; 699 properties = [NSMutableDictionary dictionary];
688 objc_setAssociatedObject(window_, &kWindowPropertiesKey, 700 objc_setAssociatedObject(window_, &kWindowPropertiesKey,
689 properties, OBJC_ASSOCIATION_RETAIN); 701 properties, OBJC_ASSOCIATION_RETAIN);
690 } 702 }
691 return properties; 703 return properties;
692 } 704 }
693 705
694 } // namespace views 706 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.h ('k') | ui/views/cocoa/native_widget_mac_nswindow.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698