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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
// Copyright (c) 2010 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_CHROMEOS_FRAME_PANEL_CONTROLLER_H_
#define CHROME_BROWSER_CHROMEOS_FRAME_PANEL_CONTROLLER_H_
#pragma once
#include <gtk/gtk.h>
#include "app/x11_util.h"
#include "views/controls/button/button.h"
#include "third_party/cros/chromeos_wm_ipc_enums.h"
class BrowserView;
class SkBitmap;
typedef unsigned long XID;
namespace views {
class ImageButton;
class ImageView;
class Label;
class MouseEvent;
class WidgetGtk;
}
namespace chromeos {
// Controls interactions with the WM for popups / panels.
class PanelController {
public:
enum State {
INITIAL,
EXPANDED,
MINIMIZED,
};
// Delegate to control panel's appearance and behavior.
class Delegate {
public:
// Retrieves the title string of the panel.
virtual string16 GetPanelTitle() = 0;
// Retrieves the icon to use in the panel's titlebar.
virtual SkBitmap GetPanelIcon() = 0;
// Close the panel. Called when a close button is pressed.
virtual void ClosePanel() = 0;
};
PanelController(Delegate* delegate_window,
GtkWindow* window);
virtual ~PanelController() {}
// Initializes the panel controller with the initial state of the focus and
// the window bounds.
void Init(bool initial_focus, const gfx::Rect& init_bounds, XID creator_xid,
WmIpcPanelUserResizeType resize_type);
bool TitleMousePressed(const views::MouseEvent& event);
void TitleMouseReleased(const views::MouseEvent& event, bool canceled);
bool TitleMouseDragged(const views::MouseEvent& event);
bool PanelClientEvent(GdkEventClient* event);
void OnFocusIn();
void OnFocusOut();
void UpdateTitleBar();
void Close();
void SetState(State state);
private:
class TitleContentView : public views::View,
public views::ButtonListener {
public:
explicit TitleContentView(PanelController* panelController);
virtual ~TitleContentView() {}
virtual void Layout();
virtual bool OnMousePressed(const views::MouseEvent& event);
virtual void OnMouseReleased(const views::MouseEvent& event, bool canceled);
virtual bool OnMouseDragged(const views::MouseEvent& event);
void OnFocusIn();
void OnFocusOut();
void OnClose();
views::ImageView* title_icon() { return title_icon_; }
views::Label* title_label() { return title_label_; }
views::ImageButton* close_button() { return close_button_; }
// ButtonListener methods.
virtual void ButtonPressed(views::Button* sender,
const views::Event& event);
private:
views::ImageView* title_icon_;
views::Label* title_label_;
views::ImageButton* close_button_;
PanelController* panel_controller_;
DISALLOW_COPY_AND_ASSIGN(TitleContentView);
};
// Called from TitleContentView's ButtonPressed handler.
void OnCloseButtonPressed();
// Dispatches client events to PanelController instances
static bool OnPanelClientEvent(
GtkWidget* widget,
GdkEventClient* event,
PanelController* panel_controller);
// Panel's delegate.
Delegate* delegate_;
// Gtk object for content.
GtkWindow* panel_;
// X id for content.
XID panel_xid_;
// Views object representing title.
views::WidgetGtk* title_window_;
// Gtk object representing title.
GtkWidget* title_;
// X id representing title.
XID title_xid_;
// Views object, holds title and close button.
TitleContentView* title_content_;
// Is the panel expanded or collapsed?
bool expanded_;
// Is the mouse button currently down?
bool mouse_down_;
// Cursor's absolute position when the mouse button was pressed.
int mouse_down_abs_x_;
int mouse_down_abs_y_;
// Cursor's offset from the upper-left corner of the titlebar when the
// mouse button was pressed.
int mouse_down_offset_x_;
int mouse_down_offset_y_;
// Is the titlebar currently being dragged? That is, has the cursor
// moved more than kDragThreshold away from its starting position?
bool dragging_;
// GTK client event handler id.
int client_event_handler_id_;
DISALLOW_COPY_AND_ASSIGN(PanelController);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_FRAME_PANEL_CONTROLLER_H_
|