| 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_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 Loading... |
| 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 mouse_capture_.reset(new CocoaMouseCapture(this)); |
| 198 } |
| 199 |
| 200 void BridgedNativeWidget::ReleaseCapture() { |
| 201 mouse_capture_.reset(); |
| 202 } |
| 203 |
| 204 bool BridgedNativeWidget::HasCapture() { |
| 205 return mouse_capture_ && mouse_capture_->IsActive(); |
| 206 } |
| 207 |
| 194 void BridgedNativeWidget::OnWindowWillClose() { | 208 void BridgedNativeWidget::OnWindowWillClose() { |
| 195 if (parent_) | 209 if (parent_) |
| 196 parent_->RemoveChildWindow(this); | 210 parent_->RemoveChildWindow(this); |
| 197 [window_ setDelegate:nil]; | 211 [window_ setDelegate:nil]; |
| 198 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; | 212 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; |
| 199 native_widget_mac_->OnWindowWillClose(); | 213 native_widget_mac_->OnWindowWillClose(); |
| 200 } | 214 } |
| 201 | 215 |
| 202 void BridgedNativeWidget::OnFullscreenTransitionStart( | 216 void BridgedNativeWidget::OnFullscreenTransitionStart( |
| 203 bool target_fullscreen_state) { | 217 bool target_fullscreen_state) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { | 390 void BridgedNativeWidget::DispatchKeyEventPostIME(const ui::KeyEvent& key) { |
| 377 // Mac key events don't go through this, but some unit tests that use | 391 // Mac key events don't go through this, but some unit tests that use |
| 378 // MockInputMethod do. | 392 // MockInputMethod do. |
| 379 DCHECK(focus_manager_); | 393 DCHECK(focus_manager_); |
| 380 native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); | 394 native_widget_mac_->GetWidget()->OnKeyEvent(const_cast<ui::KeyEvent*>(&key)); |
| 381 if (!key.handled()) | 395 if (!key.handled()) |
| 382 focus_manager_->OnKeyEvent(key); | 396 focus_manager_->OnKeyEvent(key); |
| 383 } | 397 } |
| 384 | 398 |
| 385 //////////////////////////////////////////////////////////////////////////////// | 399 //////////////////////////////////////////////////////////////////////////////// |
| 400 // BridgedNativeWidget, CocoaMouseCaptureDelegate: |
| 401 |
| 402 void BridgedNativeWidget::PostCapturedEvent(NSEvent* event) { |
| 403 [bridged_view_ processCapturedMouseEvent:event]; |
| 404 } |
| 405 |
| 406 void BridgedNativeWidget::OnMouseCaptureLost() { |
| 407 native_widget_mac_->GetWidget()->OnMouseCaptureLost(); |
| 408 } |
| 409 |
| 410 //////////////////////////////////////////////////////////////////////////////// |
| 386 // BridgedNativeWidget, FocusChangeListener: | 411 // BridgedNativeWidget, FocusChangeListener: |
| 387 | 412 |
| 388 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before, | 413 void BridgedNativeWidget::OnWillChangeFocus(View* focused_before, |
| 389 View* focused_now) { | 414 View* focused_now) { |
| 390 } | 415 } |
| 391 | 416 |
| 392 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before, | 417 void BridgedNativeWidget::OnDidChangeFocus(View* focused_before, |
| 393 View* focused_now) { | 418 View* focused_now) { |
| 394 ui::TextInputClient* input_client = | 419 ui::TextInputClient* input_client = |
| 395 focused_now ? focused_now->GetTextInputClient() : NULL; | 420 focused_now ? focused_now->GetTextInputClient() : NULL; |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 DCHECK(compositor_superview_); | 596 DCHECK(compositor_superview_); |
| 572 gfx::Size size_in_dip = GetClientAreaSize(); | 597 gfx::Size size_in_dip = GetClientAreaSize(); |
| 573 layer()->SetBounds(gfx::Rect(size_in_dip)); | 598 layer()->SetBounds(gfx::Rect(size_in_dip)); |
| 574 | 599 |
| 575 float scale_factor = GetDeviceScaleFactorFromView(compositor_superview_); | 600 float scale_factor = GetDeviceScaleFactorFromView(compositor_superview_); |
| 576 compositor_->SetScaleAndSize(scale_factor, | 601 compositor_->SetScaleAndSize(scale_factor, |
| 577 ConvertSizeToPixel(scale_factor, size_in_dip)); | 602 ConvertSizeToPixel(scale_factor, size_in_dip)); |
| 578 } | 603 } |
| 579 | 604 |
| 580 } // namespace views | 605 } // namespace views |
| OLD | NEW |