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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright (c) 2009 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_VIEWS_WIDGET_WIDGET_GTK_H_
#define CHROME_VIEWS_WIDGET_WIDGET_GTK_H_
#include <gtk/gtk.h>
#include "base/message_loop.h"
#include "chrome/views/widget/widget.h"
namespace gfx {
class Rect;
}
namespace views {
class View;
class WidgetGtk : public Widget {
public:
static WidgetGtk* Construct() {
// This isn't used, but exists to force WidgetGtk to be instantiable.
return new WidgetGtk;
}
WidgetGtk();
virtual ~WidgetGtk();
// Initializes this widget and returns the gtk drawing area for the caller to
// add to its hierarchy. (We can't pass in the parent to this method because
// there are no standard adding semantics in gtk...)
void Init(const gfx::Rect& bounds, bool has_own_focus_manager);
virtual void SetContentsView(View* view);
// Overridden from Widget:
virtual void GetBounds(gfx::Rect* out, bool including_frame) const;
virtual gfx::NativeView GetNativeView() const;
virtual void PaintNow(const gfx::Rect& update_rect);
virtual RootView* GetRootView();
virtual bool IsVisible() const;
virtual bool IsActive() const;
virtual TooltipManager* GetTooltipManager();
virtual bool GetAccelerator(int cmd_id, Accelerator* accelerator);
protected:
virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) {}
virtual gboolean OnPaint(GtkWidget* widget, GdkEventExpose* event);
virtual gboolean OnEnterNotify(GtkWidget* widget, GdkEventCrossing* event);
virtual gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event);
virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event);
virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event);
virtual gboolean OnButtonRelease(GtkWidget* widget, GdkEventButton* event);
virtual gboolean OnFocusIn(GtkWidget* widget, GdkEventFocus* event) {
return false;
}
virtual gboolean OnFocusOut(GtkWidget* widget, GdkEventFocus* event) {
return false;
}
virtual gboolean OnKeyPress(GtkWidget* widget, GdkEventKey* event);
virtual gboolean OnKeyRelease(GtkWidget* widget, GdkEventKey* event);
virtual gboolean OnScroll(GtkWidget* widget, GdkEventScroll* event) {
return false;
}
virtual gboolean OnVisibilityNotify(GtkWidget* widget,
GdkEventVisibility* event) {
return false;
}
private:
virtual RootView* CreateRootView();
// Process a mouse click
bool ProcessMousePressed(GdkEventButton* event);
void ProcessMouseReleased(GdkEventButton* event);
// Sets and retrieves the WidgetGtk in the userdata section of the widget.
static WidgetGtk* GetViewForNative(GtkWidget* widget);
static void SetViewForNative(GtkWidget* widget, WidgetGtk* view);
static RootView* GetRootViewForWidget(GtkWidget* widget);
static void SetRootViewForWidget(GtkWidget* widget, RootView* root_view);
// A set of static signal handlers that bridge
static void CallSizeAllocate(GtkWidget* widget, GtkAllocation* allocation);
static gboolean CallPaint(GtkWidget* widget, GdkEventExpose* event);
static gboolean CallEnterNotify(GtkWidget* widget, GdkEventCrossing* event);
static gboolean CallLeaveNotify(GtkWidget* widget, GdkEventCrossing* event);
static gboolean CallMotionNotify(GtkWidget* widget, GdkEventMotion* event);
static gboolean CallButtonPress(GtkWidget* widget, GdkEventButton* event);
static gboolean CallButtonRelease(GtkWidget* widget, GdkEventButton* event);
static gboolean CallFocusIn(GtkWidget* widget, GdkEventFocus* event);
static gboolean CallFocusOut(GtkWidget* widget, GdkEventFocus* event);
static gboolean CallKeyPress(GtkWidget* widget, GdkEventKey* event);
static gboolean CallKeyRelease(GtkWidget* widget, GdkEventKey* event);
static gboolean CallScroll(GtkWidget* widget, GdkEventScroll* event);
static gboolean CallVisibilityNotify(GtkWidget* widget,
GdkEventVisibility* event);
// Our native view.
GtkWidget* widget_;
// The root of the View hierarchy attached to this window.
scoped_ptr<RootView> root_view_;
// If true, the mouse is currently down.
bool is_mouse_down_;
// The following are used to detect duplicate mouse move events and not
// deliver them. Displaying a window may result in the system generating
// duplicate move events even though the mouse hasn't moved.
// If true, the last event was a mouse move event.
bool last_mouse_event_was_move_;
// Coordinates of the last mouse move event, in screen coordinates.
int last_mouse_move_x_;
int last_mouse_move_y_;
};
} // namespace views
#endif // CHROME_VIEWS_WIDGET_WIDGET_GTK_H_
|