summaryrefslogtreecommitdiffstats
path: root/content/renderer/render_view_mouse_lock_dispatcher.cc
blob: bdd747b044e3346feb8e94549d549d1232671807 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/renderer/render_view_mouse_lock_dispatcher.h"

#include "content/common/view_messages.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebWidget.h"

using blink::WebUserGestureIndicator;

namespace content {

RenderViewMouseLockDispatcher::RenderViewMouseLockDispatcher(
    RenderViewImpl* render_view_impl)
    : RenderViewObserver(render_view_impl),
      render_view_impl_(render_view_impl) {
}

RenderViewMouseLockDispatcher::~RenderViewMouseLockDispatcher() {
}

void RenderViewMouseLockDispatcher::SendLockMouseRequest(
    bool unlocked_by_target) {
  bool user_gesture = WebUserGestureIndicator::isProcessingUserGesture();

  Send(new ViewHostMsg_LockMouse(routing_id(), user_gesture, unlocked_by_target,
                                 false));
}

void RenderViewMouseLockDispatcher::SendUnlockMouseRequest() {
  Send(new ViewHostMsg_UnlockMouse(routing_id()));
}

bool RenderViewMouseLockDispatcher::OnMessageReceived(
    const IPC::Message& message) {
  bool handled = true;
  IPC_BEGIN_MESSAGE_MAP(RenderViewMouseLockDispatcher, message)
    IPC_MESSAGE_HANDLER(ViewMsg_LockMouse_ACK, OnLockMouseACK)
    IPC_MESSAGE_FORWARD(ViewMsg_MouseLockLost,
                        static_cast<MouseLockDispatcher*>(this),
                        MouseLockDispatcher::OnMouseLockLost)
    IPC_MESSAGE_UNHANDLED(handled = false)
  IPC_END_MESSAGE_MAP()
  return handled;
}

void RenderViewMouseLockDispatcher::OnLockMouseACK(bool succeeded) {
  // Notify the base class.
  MouseLockDispatcher::OnLockMouseACK(succeeded);

  // Mouse Lock removes the system cursor and provides all mouse motion as
  // .movementX/Y values on events all sent to a fixed target. This requires
  // content to specifically request the mode to be entered.
  // Mouse Capture is implicitly given for the duration of a drag event, and
  // sends all mouse events to the initial target of the drag.
  // If Lock is entered it supercedes any in progress Capture.
  if (succeeded && render_view_impl_->GetWidget()->webwidget())
    render_view_impl_->GetWidget()->webwidget()->mouseCaptureLost();
}

}  // namespace content