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

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

Issue 789763002: MacViews: Implement capture using NSEvent local+global monitors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@20140812-MacViews-LAYERS2-PRESQUASH
Patch Set: fix sorting Created 6 years 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/cocoa_mouse_capture.h » ('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 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #import "base/mac/sdk_forward_declarations.h" 9 #import "base/mac/sdk_forward_declarations.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
11 #include "ui/base/ime/input_method.h" 11 #include "ui/base/ime/input_method.h"
12 #include "ui/base/ime/input_method_factory.h" 12 #include "ui/base/ime/input_method_factory.h"
13 #include "ui/base/ui_base_switches_util.h" 13 #include "ui/base/ui_base_switches_util.h"
14 #include "ui/gfx/display.h" 14 #include "ui/gfx/display.h"
15 #include "ui/gfx/geometry/dip_util.h" 15 #include "ui/gfx/geometry/dip_util.h"
16 #import "ui/gfx/mac/coordinate_conversion.h" 16 #import "ui/gfx/mac/coordinate_conversion.h"
17 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
18 #import "ui/views/cocoa/cocoa_mouse_capture.h"
18 #import "ui/views/cocoa/bridged_content_view.h" 19 #import "ui/views/cocoa/bridged_content_view.h"
19 #import "ui/views/cocoa/views_nswindow_delegate.h" 20 #import "ui/views/cocoa/views_nswindow_delegate.h"
20 #include "ui/views/widget/native_widget_mac.h" 21 #include "ui/views/widget/native_widget_mac.h"
21 #include "ui/views/ime/input_method_bridge.h" 22 #include "ui/views/ime/input_method_bridge.h"
22 #include "ui/views/ime/null_input_method.h" 23 #include "ui/views/ime/null_input_method.h"
23 #include "ui/views/view.h" 24 #include "ui/views/view.h"
24 #include "ui/views/views_delegate.h" 25 #include "ui/views/views_delegate.h"
25 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
26 27
27 namespace { 28 namespace {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (parent()) 185 if (parent())
185 parent_window_number = [parent()->ns_window() windowNumber]; 186 parent_window_number = [parent()->ns_window() windowNumber];
186 187
187 [window_ orderWindow:NSWindowAbove 188 [window_ orderWindow:NSWindowAbove
188 relativeTo:parent_window_number]; 189 relativeTo:parent_window_number];
189 } 190 }
190 DCHECK(window_visible_); 191 DCHECK(window_visible_);
191 NotifyVisibilityChangeDown(); 192 NotifyVisibilityChangeDown();
192 } 193 }
193 194
195 void BridgedNativeWidget::AcquireCapture() {
196 DCHECK(!HasCapture());
197 if (!window_visible_)
198 return; // Capture on hidden windows is disallowed.
199
200 mouse_capture_.reset(new CocoaMouseCapture(this));
201 }
202
203 void BridgedNativeWidget::ReleaseCapture() {
204 mouse_capture_.reset();
205 }
206
207 bool BridgedNativeWidget::HasCapture() {
208 return mouse_capture_ && mouse_capture_->IsActive();
209 }
210
194 void BridgedNativeWidget::OnWindowWillClose() { 211 void BridgedNativeWidget::OnWindowWillClose() {
195 if (parent_) 212 if (parent_)
196 parent_->RemoveChildWindow(this); 213 parent_->RemoveChildWindow(this);
197 [window_ setDelegate:nil]; 214 [window_ setDelegate:nil];
198 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; 215 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_];
199 native_widget_mac_->OnWindowWillClose(); 216 native_widget_mac_->OnWindowWillClose();
200 } 217 }
201 218
202 void BridgedNativeWidget::OnFullscreenTransitionStart( 219 void BridgedNativeWidget::OnFullscreenTransitionStart(
203 bool target_fullscreen_state) { 220 bool target_fullscreen_state) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 304
288 window_visible_ = new_visibility; 305 window_visible_ = new_visibility;
289 306
290 // If arriving via SetVisible(), |wants_to_be_visible_| should already be set. 307 // If arriving via SetVisible(), |wants_to_be_visible_| should already be set.
291 // If made visible externally (e.g. Cmd+H), just roll with it. Don't try (yet) 308 // If made visible externally (e.g. Cmd+H), just roll with it. Don't try (yet)
292 // to distinguish being *hidden* externally from being hidden by a parent 309 // to distinguish being *hidden* externally from being hidden by a parent
293 // window - we might not need that. 310 // window - we might not need that.
294 if (window_visible_) 311 if (window_visible_)
295 wants_to_be_visible_ = true; 312 wants_to_be_visible_ = true;
296 313
314 // Capture on hidden windows is not permitted.
315 if (!window_visible_)
316 mouse_capture_.reset();
317
297 // TODO(tapted): Investigate whether we want this for Mac. This is what Aura 318 // TODO(tapted): Investigate whether we want this for Mac. This is what Aura
298 // does, and it is what tests expect. However, because layer drawing is 319 // does, and it is what tests expect. However, because layer drawing is
299 // asynchronous (and things like deminiaturize in AppKit are not), it can 320 // asynchronous (and things like deminiaturize in AppKit are not), it can
300 // result in a CALayer appearing on screen before it has been redrawn in the 321 // result in a CALayer appearing on screen before it has been redrawn in the
301 // GPU process. This is a general problem. In content, a helper class, 322 // GPU process. This is a general problem. In content, a helper class,
302 // RenderWidgetResizeHelper, blocks the UI thread in -[NSView setFrameSize:] 323 // RenderWidgetResizeHelper, blocks the UI thread in -[NSView setFrameSize:]
303 // and RenderWidgetHostView::Show() until a frame is ready. 324 // and RenderWidgetHostView::Show() until a frame is ready.
304 if (layer()) { 325 if (layer()) {
305 layer()->SetVisible(window_visible_); 326 layer()->SetVisible(window_visible_);
306 layer()->SchedulePaint(gfx::Rect(GetClientAreaSize())); 327 layer()->SchedulePaint(gfx::Rect(GetClientAreaSize()));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { 397 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) {
377 // Mac key events don't go through this, but some unit tests that use 398 // Mac key events don't go through this, but some unit tests that use
378 // MockInputMethod do. 399 // MockInputMethod do.
379 DCHECK(focus_manager_); 400 DCHECK(focus_manager_);
380 native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); 401 native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key));
381 if (!key.handled()) 402 if (!key.handled())
382 focus_manager_->OnKeyEvent(key); 403 focus_manager_->OnKeyEvent(key);
383 } 404 }
384 405
385 //////////////////////////////////////////////////////////////////////////////// 406 ////////////////////////////////////////////////////////////////////////////////
407 // BridgedNativeWidget, CocoaMouseCaptureDelegate:
408
409 void BridgedNativeWidget::PostCapturedEvent(NSEvent* event) {
410 [bridged_view_ processCapturedMouseEvent:event];
411 }
412
413 void BridgedNativeWidget::OnMouseCaptureLost() {
414 native_widget_mac_->GetWidget()->OnMouseCaptureLost();
415 }
416
417 ////////////////////////////////////////////////////////////////////////////////
386 // BridgedNativeWidget, FocusChangeListener: 418 // BridgedNativeWidget, FocusChangeListener:
387 419
388 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before, 420 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before,
389 View* focused_now) { 421 View* focused_now) {
390 } 422 }
391 423
392 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before, 424 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before,
393 View* focused_now) { 425 View* focused_now) {
394 ui::TextInputClient* input_client = 426 ui::TextInputClient* input_client =
395 focused_now ? focused_now->GetTextInputClient() : NULL; 427 focused_now ? focused_now->GetTextInputClient() : NULL;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 DCHECK(compositor_superview_); 603 DCHECK(compositor_superview_);
572 gfx::Size size_in_dip = GetClientAreaSize(); 604 gfx::Size size_in_dip = GetClientAreaSize();
573 layer()->SetBounds(gfx::Rect(size_in_dip)); 605 layer()->SetBounds(gfx::Rect(size_in_dip));
574 606
575 float scale_factor = GetDeviceScaleFactorFromView(compositor_superview_); 607 float scale_factor = GetDeviceScaleFactorFromView(compositor_superview_);
576 compositor_->SetScaleAndSize(scale_factor, 608 compositor_->SetScaleAndSize(scale_factor,
577 ConvertSizeToPixel(scale_factor, size_in_dip)); 609 ConvertSizeToPixel(scale_factor, size_in_dip));
578 } 610 }
579 611
580 } // namespace views 612 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/cocoa/bridged_native_widget.h ('k') | ui/views/cocoa/cocoa_mouse_capture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698