Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / gfx / win / direct_manipulation.cc
blob2014c7088544c26b0ec188b78011d4f989c7e208
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.
5 #include "ui/gfx/win/direct_manipulation.h"
7 #include "base/basictypes.h"
8 #include "base/win/windows_version.h"
10 namespace gfx {
11 namespace win {
13 // static
14 scoped_ptr<DirectManipulationHelper>
15 DirectManipulationHelper::CreateInstance() {
16 scoped_ptr<DirectManipulationHelper> instance;
18 if (base::win::GetVersion() >= base::win::VERSION_WIN10)
19 instance.reset(new DirectManipulationHelper);
21 return instance.Pass();
24 DirectManipulationHelper::DirectManipulationHelper() {}
26 DirectManipulationHelper::~DirectManipulationHelper() {}
28 void DirectManipulationHelper::Initialize(HWND window) {
29 DCHECK(::IsWindow(window));
31 // TODO(ananta)
32 // Remove the CHECK statements here and below and replace them with logs
33 // when this code stabilizes.
34 HRESULT hr = manager_.CreateInstance(CLSID_DirectManipulationManager,
35 nullptr, CLSCTX_INPROC_SERVER);
36 CHECK(SUCCEEDED(hr));
38 hr = compositor_.CreateInstance(CLSID_DCompManipulationCompositor,
39 nullptr, CLSCTX_INPROC_SERVER);
40 CHECK(SUCCEEDED(hr));
42 hr = manager_->GetUpdateManager(IID_PPV_ARGS(update_manager_.Receive()));
43 CHECK(SUCCEEDED(hr));
45 hr = compositor_->SetUpdateManager(update_manager_.get());
46 CHECK(SUCCEEDED(hr));
48 hr = frame_info_.QueryFrom(compositor_.get());
49 CHECK(SUCCEEDED(hr));
51 hr = manager_->CreateViewport(frame_info_.get(), window,
52 IID_PPV_ARGS(view_port_outer_.Receive()));
53 CHECK(SUCCEEDED(hr));
56 // Enable the desired configuration for each viewport.
58 DIRECTMANIPULATION_CONFIGURATION configuration =
59 DIRECTMANIPULATION_CONFIGURATION_INTERACTION
60 | DIRECTMANIPULATION_CONFIGURATION_TRANSLATION_X
61 | DIRECTMANIPULATION_CONFIGURATION_TRANSLATION_Y
62 | DIRECTMANIPULATION_CONFIGURATION_TRANSLATION_INERTIA
63 | DIRECTMANIPULATION_CONFIGURATION_RAILS_X
64 | DIRECTMANIPULATION_CONFIGURATION_RAILS_Y
65 | DIRECTMANIPULATION_CONFIGURATION_SCALING
66 | DIRECTMANIPULATION_CONFIGURATION_SCALING_INERTIA;
68 hr = view_port_outer_->ActivateConfiguration(configuration);
69 CHECK(SUCCEEDED(hr));
72 void DirectManipulationHelper::SetBounds(const gfx::Rect& bounds) {
73 base::win::ScopedComPtr<IDirectManipulationPrimaryContent>
74 primary_content_outer;
75 HRESULT hr = view_port_outer_->GetPrimaryContent(
76 IID_PPV_ARGS(primary_content_outer.Receive()));
77 CHECK(SUCCEEDED(hr));
79 base::win::ScopedComPtr<IDirectManipulationContent> content_outer;
80 hr = content_outer.QueryFrom(primary_content_outer.get());
81 CHECK(SUCCEEDED(hr));
83 RECT rect = bounds.ToRECT();
85 hr = view_port_outer_->SetViewportRect(&rect);
86 CHECK(SUCCEEDED(hr));
88 hr = content_outer->SetContentRect(&rect);
89 CHECK(SUCCEEDED(hr));
92 void DirectManipulationHelper::Activate(HWND window) {
93 DCHECK(::IsWindow(window));
94 manager_->Activate(window);
97 void DirectManipulationHelper::Deactivate(HWND window) {
98 DCHECK(::IsWindow(window));
99 manager_->Deactivate(window);
102 void DirectManipulationHelper:: HandleMouseWheel(HWND window, UINT message,
103 WPARAM w_param, LPARAM l_param) {
104 MSG msg = { window, message, w_param, l_param};
106 HRESULT hr = view_port_outer_->SetContact(DIRECTMANIPULATION_MOUSEFOCUS);
107 if (SUCCEEDED(hr)) {
108 BOOL handled = FALSE;
109 manager_->ProcessInput(&msg, &handled);
110 view_port_outer_->ReleaseContact(DIRECTMANIPULATION_MOUSEFOCUS);
114 } // namespace win.
115 } // namespace gfx.