forked from nwjs/nw.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup_controller_common.h
105 lines (82 loc) · 3.86 KB
/
popup_controller_common.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 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_AUTOFILL_POPUP_CONTROLLER_COMMON_H_
#define CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_
#include "content/public/browser/render_widget_host.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
namespace content {
struct NativeWebKeyboardEvent;
class RenderViewHost;
class WebContents;
}
namespace gfx {
class Display;
}
namespace autofill {
// Class that controls common functionality for Autofill style popups. Can
// determine the correct location of a popup of a desired size and can register
// a handler to key press events.
class PopupControllerCommon {
public:
PopupControllerCommon(const gfx::RectF& element_bounds,
gfx::NativeView container_view,
content::WebContents* web_contents);
virtual ~PopupControllerCommon();
const gfx::RectF& element_bounds() const { return element_bounds_; }
gfx::NativeView container_view() { return container_view_; }
content::WebContents* web_contents() { return web_contents_; }
// Returns the enclosing rectangle for |element_bounds_|.
const gfx::Rect RoundedElementBounds() const;
// Returns the bounds that the popup should be placed at, given the desired
// width and height. By default this places the popup below |element_bounds|
// but it will be placed above if there isn't enough space.
gfx::Rect GetPopupBounds(int desired_width, int desired_height) const;
// Callback used to register with RenderViewHost. This can only be set once,
// or else a callback may be registered that will not be removed
// (crbug.com/338070). Call will crash if callback is already set.
void SetKeyPressCallback(content::RenderWidgetHost::KeyPressEventCallback);
// Register listener for key press events with the current RenderViewHost
// associated with |web_contents_|. If callback has already been registered,
// this has no effect.
void RegisterKeyPressCallback();
// Remove previously registered callback, assuming that the current
// RenderViewHost is the same as when it was originally registered. Safe to
// call even if the callback is not currently registered.
void RemoveKeyPressCallback();
protected:
// A helper function to get the display closest to the given point (virtual
// for testing).
virtual gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const;
private:
// Calculates the width of the popup and the x position of it. These values
// will stay on the screen.
std::pair<int, int> CalculatePopupXAndWidth(
const gfx::Display& left_display,
const gfx::Display& right_display,
int popup_required_width) const;
// Calculates the height of the popup and the y position of it. These values
// will stay on the screen.
std::pair<int, int> CalculatePopupYAndHeight(
const gfx::Display& top_display,
const gfx::Display& bottom_display,
int popup_required_height) const;
// The bounds of the text element that is the focus of the popup.
// These coordinates are in screen space.
gfx::RectF element_bounds_;
// Weak reference
gfx::NativeView container_view_;
// The WebContents in which this object should listen for keyboard events
// while showing the popup. Can be NULL, in which case this object will not
// listen for keyboard events.
content::WebContents* web_contents_;
// The RenderViewHost that this object has registered its keyboard press
// callback with.
content::RenderViewHost* key_press_event_target_;
content::RenderWidgetHost::KeyPressEventCallback key_press_event_callback_;
DISALLOW_COPY_AND_ASSIGN(PopupControllerCommon);
};
} // namespace autofill
#endif // CHROME_BROWSER_UI_AUTOFILL_POPUP_CONTROLLER_COMMON_H_