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"
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
));
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
);
38 hr
= compositor_
.CreateInstance(CLSID_DCompManipulationCompositor
,
39 nullptr, CLSCTX_INPROC_SERVER
);
42 hr
= manager_
->GetUpdateManager(IID_PPV_ARGS(update_manager_
.Receive()));
45 hr
= compositor_
->SetUpdateManager(update_manager_
.get());
48 hr
= frame_info_
.QueryFrom(compositor_
.get());
51 hr
= manager_
->CreateViewport(frame_info_
.get(), window
,
52 IID_PPV_ARGS(view_port_outer_
.Receive()));
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
);
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()));
79 base::win::ScopedComPtr
<IDirectManipulationContent
> content_outer
;
80 hr
= content_outer
.QueryFrom(primary_content_outer
.get());
83 RECT rect
= bounds
.ToRECT();
85 hr
= view_port_outer_
->SetViewportRect(&rect
);
88 hr
= content_outer
->SetContentRect(&rect
);
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
);
108 BOOL handled
= FALSE
;
109 manager_
->ProcessInput(&msg
, &handled
);
110 view_port_outer_
->ReleaseContact(DIRECTMANIPULATION_MOUSEFOCUS
);