OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gfx/win/direct_manipulation.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/win/windows_version.h" |
| 9 |
| 10 namespace gfx { |
| 11 namespace win { |
| 12 |
| 13 // static |
| 14 DirectManipulationHelper* DirectManipulationHelper::CreateInstance() { |
| 15 if (base::win::GetVersion() >= base::win::VERSION_WIN10) |
| 16 return new DirectManipulationHelper; |
| 17 return NULL; |
| 18 } |
| 19 |
| 20 void DirectManipulationHelper::Initialize(HWND window) { |
| 21 DCHECK(::IsWindow(window)); |
| 22 |
| 23 // TODO(ananta) |
| 24 // Remove the CHECK statements here and below and replace them with logs |
| 25 // when this code stabilizes. |
| 26 HRESULT hr = manager_.CreateInstance(CLSID_DirectManipulationManager, |
| 27 nullptr, CLSCTX_INPROC_SERVER); |
| 28 CHECK(SUCCEEDED(hr)); |
| 29 |
| 30 hr = compositor_.CreateInstance(CLSID_DCompManipulationCompositor, |
| 31 nullptr, CLSCTX_INPROC_SERVER); |
| 32 CHECK(SUCCEEDED(hr)); |
| 33 |
| 34 hr = manager_->GetUpdateManager(IID_PPV_ARGS(update_manager_.Receive())); |
| 35 CHECK(SUCCEEDED(hr)); |
| 36 |
| 37 hr = compositor_->SetUpdateManager(update_manager_.get()); |
| 38 CHECK(SUCCEEDED(hr)); |
| 39 |
| 40 hr = frame_info_.QueryFrom(compositor_.get()); |
| 41 CHECK(SUCCEEDED(hr)); |
| 42 |
| 43 hr = manager_->CreateViewport(frame_info_.get(), window, |
| 44 IID_PPV_ARGS(view_port_outer_.Receive())); |
| 45 CHECK(SUCCEEDED(hr)); |
| 46 |
| 47 // |
| 48 // Enable the desired configuration for each viewport. |
| 49 // |
| 50 DIRECTMANIPULATION_CONFIGURATION configuration = |
| 51 DIRECTMANIPULATION_CONFIGURATION_INTERACTION |
| 52 | DIRECTMANIPULATION_CONFIGURATION_TRANSLATION_X |
| 53 | DIRECTMANIPULATION_CONFIGURATION_TRANSLATION_Y |
| 54 | DIRECTMANIPULATION_CONFIGURATION_TRANSLATION_INERTIA |
| 55 | DIRECTMANIPULATION_CONFIGURATION_RAILS_X |
| 56 | DIRECTMANIPULATION_CONFIGURATION_RAILS_Y |
| 57 | DIRECTMANIPULATION_CONFIGURATION_SCALING |
| 58 | DIRECTMANIPULATION_CONFIGURATION_SCALING_INERTIA; |
| 59 |
| 60 hr = view_port_outer_->ActivateConfiguration(configuration); |
| 61 CHECK(SUCCEEDED(hr)); |
| 62 } |
| 63 |
| 64 void DirectManipulationHelper::SetBounds(const gfx::Rect& bounds) { |
| 65 base::win::ScopedComPtr<IDirectManipulationPrimaryContent> |
| 66 primary_content_outer; |
| 67 HRESULT hr = view_port_outer_->GetPrimaryContent( |
| 68 IID_PPV_ARGS(primary_content_outer.Receive())); |
| 69 CHECK(SUCCEEDED(hr)); |
| 70 |
| 71 base::win::ScopedComPtr<IDirectManipulationContent> content_outer; |
| 72 hr = content_outer.QueryFrom(primary_content_outer.get()); |
| 73 CHECK(SUCCEEDED(hr)); |
| 74 |
| 75 RECT rect = bounds.ToRECT(); |
| 76 |
| 77 hr = view_port_outer_->SetViewportRect(&rect); |
| 78 CHECK(SUCCEEDED(hr)); |
| 79 |
| 80 hr = content_outer->SetContentRect(&rect); |
| 81 CHECK(SUCCEEDED(hr)); |
| 82 } |
| 83 |
| 84 void DirectManipulationHelper::Activate(HWND window) { |
| 85 DCHECK(::IsWindow(window)); |
| 86 HRESULT hr = manager_->Activate(window); |
| 87 CHECK(SUCCEEDED(hr)); |
| 88 } |
| 89 |
| 90 void DirectManipulationHelper:: HandleMouseWheel(HWND window, UINT message, |
| 91 WPARAM w_param, LPARAM l_param) { |
| 92 MSG msg = { window, message, w_param, l_param}; |
| 93 |
| 94 HRESULT hr = view_port_outer_->SetContact(DIRECTMANIPULATION_MOUSEFOCUS); |
| 95 if (SUCCEEDED(hr)) { |
| 96 BOOL handled = FALSE; |
| 97 manager_->ProcessInput(&msg, &handled); |
| 98 view_port_outer_->ReleaseContact(DIRECTMANIPULATION_MOUSEFOCUS); |
| 99 } |
| 100 } |
| 101 |
| 102 } // namespace win. |
| 103 } // namespace gfx. |
OLD | NEW |