| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_FRAME_PANEL_CONTROLLER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_FRAME_PANEL_CONTROLLER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <gtk/gtk.h> | |
| 10 | |
| 11 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" | |
| 12 #include "ui/base/x/x11_util.h" | |
| 13 #include "ui/views/controls/button/button.h" | |
| 14 | |
| 15 class SkBitmap; | |
| 16 typedef unsigned long XID; | |
| 17 | |
| 18 namespace base { | |
| 19 class Time; | |
| 20 } | |
| 21 | |
| 22 namespace views { | |
| 23 class ImageButton; | |
| 24 class ImageView; | |
| 25 class Label; | |
| 26 class MouseEvent; | |
| 27 class Widget; | |
| 28 } | |
| 29 | |
| 30 namespace chromeos { | |
| 31 | |
| 32 // Controls interactions with the WM for popups / panels. | |
| 33 class PanelController { | |
| 34 public: | |
| 35 enum State { | |
| 36 INITIAL, | |
| 37 EXPANDED, | |
| 38 MINIMIZED, | |
| 39 }; | |
| 40 | |
| 41 // Delegate to control panel's appearance and behavior. | |
| 42 class Delegate { | |
| 43 public: | |
| 44 // Retrieves the title string of the panel. | |
| 45 virtual string16 GetPanelTitle() = 0; | |
| 46 | |
| 47 // Retrieves the icon to use in the panel's titlebar. | |
| 48 virtual SkBitmap GetPanelIcon() = 0; | |
| 49 | |
| 50 // Can the panel be closed? Called before ClosePanel() when the close | |
| 51 // button is pressed to give beforeunload handlers a chance to cancel. | |
| 52 virtual bool CanClosePanel() = 0; | |
| 53 | |
| 54 // Close the panel. Called when a close button is pressed. | |
| 55 virtual void ClosePanel() = 0; | |
| 56 | |
| 57 // Activate the panel. Called when maximized. | |
| 58 virtual void ActivatePanel() = 0; | |
| 59 }; | |
| 60 | |
| 61 PanelController(Delegate* delegate_window, | |
| 62 GtkWindow* window); | |
| 63 virtual ~PanelController() {} | |
| 64 | |
| 65 // Initializes the panel controller with the initial state of the focus and | |
| 66 // the window bounds. | |
| 67 void Init(bool initial_focus, const gfx::Rect& init_bounds, XID creator_xid, | |
| 68 WmIpcPanelUserResizeType resize_type); | |
| 69 | |
| 70 bool TitleMousePressed(const views::MouseEvent& event); | |
| 71 void TitleMouseReleased(const views::MouseEvent& event); | |
| 72 void TitleMouseCaptureLost(); | |
| 73 bool TitleMouseDragged(const views::MouseEvent& event); | |
| 74 bool PanelClientEvent(GdkEventClient* event); | |
| 75 void OnFocusIn(); | |
| 76 void OnFocusOut(); | |
| 77 | |
| 78 void UpdateTitleBar(); | |
| 79 void SetUrgent(bool urgent); | |
| 80 void Close(); | |
| 81 | |
| 82 void SetState(State state); | |
| 83 | |
| 84 bool urgent() { return urgent_; } | |
| 85 | |
| 86 private: | |
| 87 class TitleContentView : public views::View, | |
| 88 public views::ButtonListener { | |
| 89 public: | |
| 90 explicit TitleContentView(PanelController* panelController); | |
| 91 virtual ~TitleContentView(); | |
| 92 | |
| 93 // Overridden from View: | |
| 94 virtual void Layout() OVERRIDE; | |
| 95 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; | |
| 96 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; | |
| 97 virtual void OnMouseCaptureLost() OVERRIDE; | |
| 98 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; | |
| 99 | |
| 100 void OnFocusIn(); | |
| 101 void OnFocusOut(); | |
| 102 void OnClose(); | |
| 103 | |
| 104 views::ImageView* title_icon() { return title_icon_; } | |
| 105 views::Label* title_label() { return title_label_; } | |
| 106 views::ImageButton* close_button() { return close_button_; } | |
| 107 | |
| 108 // ButtonListener methods. | |
| 109 virtual void ButtonPressed(views::Button* sender, | |
| 110 const views::Event& event) OVERRIDE; | |
| 111 private: | |
| 112 views::ImageView* title_icon_; | |
| 113 views::Label* title_label_; | |
| 114 views::ImageButton* close_button_; | |
| 115 PanelController* panel_controller_; | |
| 116 DISALLOW_COPY_AND_ASSIGN(TitleContentView); | |
| 117 }; | |
| 118 | |
| 119 // Called from TitleContentView's ButtonPressed handler. | |
| 120 void OnCloseButtonPressed(); | |
| 121 | |
| 122 // Dispatches client events to PanelController instances | |
| 123 static bool OnPanelClientEvent( | |
| 124 GtkWidget* widget, | |
| 125 GdkEventClient* event, | |
| 126 PanelController* panel_controller); | |
| 127 | |
| 128 // Panel's delegate. | |
| 129 Delegate* delegate_; | |
| 130 | |
| 131 // Gtk object for content. | |
| 132 GtkWindow* panel_; | |
| 133 // X id for content. | |
| 134 XID panel_xid_; | |
| 135 | |
| 136 // Views object representing title. | |
| 137 views::Widget* title_window_; | |
| 138 // Gtk object representing title. | |
| 139 GtkWidget* title_; | |
| 140 // X id representing title. | |
| 141 XID title_xid_; | |
| 142 | |
| 143 // Views object, holds title and close button. | |
| 144 TitleContentView* title_content_; | |
| 145 | |
| 146 // Is the panel expanded or collapsed? | |
| 147 bool expanded_; | |
| 148 | |
| 149 // Is the mouse button currently down? | |
| 150 bool mouse_down_; | |
| 151 | |
| 152 // Cursor's absolute position when the mouse button was pressed. | |
| 153 int mouse_down_abs_x_; | |
| 154 int mouse_down_abs_y_; | |
| 155 | |
| 156 // Cursor's offset from the upper-left corner of the titlebar when the | |
| 157 // mouse button was pressed. | |
| 158 int mouse_down_offset_x_; | |
| 159 int mouse_down_offset_y_; | |
| 160 | |
| 161 // Is the titlebar currently being dragged? That is, has the cursor | |
| 162 // moved more than kDragThreshold away from its starting position? | |
| 163 bool dragging_; | |
| 164 | |
| 165 // GTK client event handler id. | |
| 166 int client_event_handler_id_; | |
| 167 | |
| 168 // Focused state. | |
| 169 bool focused_; | |
| 170 | |
| 171 // Urgent (highlight) state. | |
| 172 bool urgent_; | |
| 173 | |
| 174 // Timestamp to prevent setting urgent immediately after clearing it. | |
| 175 base::TimeTicks urgent_cleared_time_; | |
| 176 | |
| 177 DISALLOW_COPY_AND_ASSIGN(PanelController); | |
| 178 }; | |
| 179 | |
| 180 } // namespace chromeos | |
| 181 | |
| 182 #endif // CHROME_BROWSER_CHROMEOS_FRAME_PANEL_CONTROLLER_H_ | |
| OLD | NEW |