summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/link_disambiguation/link_disambiguation_popup.h
blob: a97233a880fba2a3dd38c46529610d10aadea7c5 (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
// Copyright (c) 2014 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.

#ifndef CHROME_BROWSER_UI_VIEWS_LINK_DISAMBIGUATION_LINK_DISAMBIGUATION_POPUP_H_
#define CHROME_BROWSER_UI_VIEWS_LINK_DISAMBIGUATION_LINK_DISAMBIGUATION_POPUP_H_

#include "base/macros.h"
#include "content/public/browser/web_contents_view_delegate.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/widget/widget.h"

namespace aura {
class Window;
}

namespace ui {
class MouseEvent;
}

// Creates a popup with a zoomed bitmap rendered by Blink of an area in web
// |content| that received an ambiguous Gesture event. This allows the user to
// select which of the links their first Gesture event overlapped. The popup
// generates a new Gesture event which is sent back to the provided |callback|.
class LinkDisambiguationPopup {
 public:
  LinkDisambiguationPopup();
  ~LinkDisambiguationPopup();

  // Creates and shows the Popup. |top_level_widget| is the active widget.
  // |zoomed_bitmap| is the scaled-up image of the ambiguous web content.
  // |target_rect| is the original, unzoomed rectangle in DIPs in the
  // coordinate system of |content|. We will convert received
  // gestures in the popup to the coordinate system of |content| and as an
  // offset within |target_rect|, and then call the |callback| with the
  // transformed coordinates GestureEvent.
  void Show(views::Widget* top_level_widget,
            const SkBitmap& zoomed_bitmap,
            const gfx::Rect& target_rect,
            const gfx::NativeView content,
            const base::Callback<void(ui::GestureEvent*)>& gesture_cb,
            const base::Callback<void(ui::MouseEvent*)>& mouse_cb);
  void Close();

 private:
  class ZoomBubbleView;

  // It is possible that |view_| can be destroyed by its widget instead of
  // closed explicitly by us. In that case we need to be notified that it has
  // been destroyed so we can invalidate our own pointer to that view.
  void InvalidateBubbleView();

  // A non-owning pointer to the calling window that contains the unzoomed web
  // content bitmap, that we will be sending the GestureEvents received back to.
  const aura::Window* content_;
  ZoomBubbleView* view_;

  DISALLOW_COPY_AND_ASSIGN(LinkDisambiguationPopup);
};

#endif  // CHROME_BROWSER_UI_VIEWS_LINK_DISAMBIGUATION_LINK_DISAMBIGUATION_POPUP_H_