OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/frame/panel_controller.h" | 5 #include "chrome/browser/chromeos/frame/panel_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 void PanelController::UpdateTitleBar() { | 158 void PanelController::UpdateTitleBar() { |
159 if (!delegate_ || !title_window_) | 159 if (!delegate_ || !title_window_) |
160 return; | 160 return; |
161 DCHECK(title_content_); | 161 DCHECK(title_content_); |
162 title_content_->title_label()->SetText( | 162 title_content_->title_label()->SetText( |
163 UTF16ToWideHack(delegate_->GetPanelTitle())); | 163 UTF16ToWideHack(delegate_->GetPanelTitle())); |
164 title_content_->title_icon()->SetImage(delegate_->GetPanelIcon()); | 164 title_content_->title_icon()->SetImage(delegate_->GetPanelIcon()); |
165 } | 165 } |
166 | 166 |
167 bool PanelController::TitleMousePressed(const views::MouseEvent& event) { | 167 bool PanelController::TitleMousePressed(const views::MouseEvent& event) { |
168 if (!event.IsOnlyLeftMouseButton()) { | 168 if (!event.IsOnlyLeftMouseButton()) |
169 return false; | 169 return false; |
170 } | |
171 GdkEvent* gdk_event = gtk_get_current_event(); | 170 GdkEvent* gdk_event = gtk_get_current_event(); |
172 if (gdk_event->type != GDK_BUTTON_PRESS) { | 171 if (gdk_event->type != GDK_BUTTON_PRESS) { |
173 gdk_event_free(gdk_event); | 172 gdk_event_free(gdk_event); |
174 NOTREACHED(); | 173 NOTREACHED(); |
175 return false; | 174 return false; |
176 } | 175 } |
177 DCHECK(title_); | 176 DCHECK(title_); |
178 // Get the last titlebar width that we saw in a ConfigureNotify event -- we | 177 // Get the last titlebar width that we saw in a ConfigureNotify event -- we |
179 // need to give drag positions in terms of the top-right corner of the | 178 // need to give drag positions in terms of the top-right corner of the |
180 // titlebar window. See WM_IPC_MESSAGE_WM_NOTIFY_PANEL_DRAGGED's declaration | 179 // titlebar window. See WM_IPC_MESSAGE_WM_NOTIFY_PANEL_DRAGGED's declaration |
181 // for details. | 180 // for details. |
182 gint title_width = 1; | 181 gint title_width = 1; |
183 gtk_window_get_size(GTK_WINDOW(title_), &title_width, NULL); | 182 gtk_window_get_size(GTK_WINDOW(title_), &title_width, NULL); |
184 | 183 |
185 GdkEventButton last_button_event = gdk_event->button; | 184 GdkEventButton last_button_event = gdk_event->button; |
186 mouse_down_ = true; | 185 mouse_down_ = true; |
187 mouse_down_abs_x_ = last_button_event.x_root; | 186 mouse_down_abs_x_ = last_button_event.x_root; |
188 mouse_down_abs_y_ = last_button_event.y_root; | 187 mouse_down_abs_y_ = last_button_event.y_root; |
189 mouse_down_offset_x_ = event.x() - title_width; | 188 mouse_down_offset_x_ = event.x() - title_width; |
190 mouse_down_offset_y_ = event.y(); | 189 mouse_down_offset_y_ = event.y(); |
191 dragging_ = false; | 190 dragging_ = false; |
192 gdk_event_free(gdk_event); | 191 gdk_event_free(gdk_event); |
193 return true; | 192 return true; |
194 } | 193 } |
195 | 194 |
196 void PanelController::TitleMouseReleased( | |
197 const views::MouseEvent& event, bool canceled) { | |
198 if (!event.IsLeftMouseButton()) { | |
199 return; | |
200 } | |
201 // Only handle clicks that started in our window. | |
202 if (!mouse_down_) { | |
203 return; | |
204 } | |
205 | |
206 mouse_down_ = false; | |
207 if (!dragging_) { | |
208 SetState(expanded_ ? | |
209 PanelController::MINIMIZED : PanelController::EXPANDED); | |
210 } else { | |
211 WmIpc::Message msg(WM_IPC_MESSAGE_WM_NOTIFY_PANEL_DRAG_COMPLETE); | |
212 msg.set_param(0, panel_xid_); | |
213 WmIpc::instance()->SendMessage(msg); | |
214 dragging_ = false; | |
215 } | |
216 } | |
217 | |
218 void PanelController::SetState(State state) { | |
219 WmIpc::Message msg(WM_IPC_MESSAGE_WM_SET_PANEL_STATE); | |
220 msg.set_param(0, panel_xid_); | |
221 msg.set_param(1, state == EXPANDED); | |
222 WmIpc::instance()->SendMessage(msg); | |
223 } | |
224 | |
225 bool PanelController::TitleMouseDragged(const views::MouseEvent& event) { | 195 bool PanelController::TitleMouseDragged(const views::MouseEvent& event) { |
226 if (!mouse_down_) { | 196 if (!mouse_down_) |
227 return false; | 197 return false; |
228 } | |
229 | |
230 GdkEvent* gdk_event = gtk_get_current_event(); | 198 GdkEvent* gdk_event = gtk_get_current_event(); |
231 if (gdk_event->type != GDK_MOTION_NOTIFY) { | 199 if (gdk_event->type != GDK_MOTION_NOTIFY) { |
232 gdk_event_free(gdk_event); | 200 gdk_event_free(gdk_event); |
233 NOTREACHED(); | 201 NOTREACHED(); |
234 return false; | 202 return false; |
235 } | 203 } |
236 GdkEventMotion last_motion_event = gdk_event->motion; | 204 GdkEventMotion last_motion_event = gdk_event->motion; |
237 if (!dragging_) { | 205 if (!dragging_) { |
238 if (views::View::ExceededDragThreshold( | 206 if (views::View::ExceededDragThreshold( |
239 last_motion_event.x_root - mouse_down_abs_x_, | 207 last_motion_event.x_root - mouse_down_abs_x_, |
240 last_motion_event.y_root - mouse_down_abs_y_)) { | 208 last_motion_event.y_root - mouse_down_abs_y_)) { |
241 dragging_ = true; | 209 dragging_ = true; |
242 } | 210 } |
243 } | 211 } |
244 if (dragging_) { | 212 if (dragging_) { |
245 WmIpc::Message msg(WM_IPC_MESSAGE_WM_NOTIFY_PANEL_DRAGGED); | 213 WmIpc::Message msg(WM_IPC_MESSAGE_WM_NOTIFY_PANEL_DRAGGED); |
246 msg.set_param(0, panel_xid_); | 214 msg.set_param(0, panel_xid_); |
247 msg.set_param(1, last_motion_event.x_root - mouse_down_offset_x_); | 215 msg.set_param(1, last_motion_event.x_root - mouse_down_offset_x_); |
248 msg.set_param(2, last_motion_event.y_root - mouse_down_offset_y_); | 216 msg.set_param(2, last_motion_event.y_root - mouse_down_offset_y_); |
249 WmIpc::instance()->SendMessage(msg); | 217 WmIpc::instance()->SendMessage(msg); |
250 } | 218 } |
251 gdk_event_free(gdk_event); | 219 gdk_event_free(gdk_event); |
252 return true; | 220 return true; |
253 } | 221 } |
254 | 222 |
223 void PanelController::TitleMouseReleased(const views::MouseEvent& event) { | |
224 if (event.IsLeftMouseButton()) | |
225 TitleMouseCaptureLost(); | |
226 } | |
227 | |
228 void PanelController::TitleMouseCaptureLost() { | |
229 // Only handle clicks that started in our window. | |
230 if (!mouse_down_) | |
231 return; | |
232 | |
233 mouse_down_ = false; | |
234 if (!dragging_) { | |
235 SetState(expanded_ ? | |
236 PanelController::MINIMIZED : PanelController::EXPANDED); | |
237 } else { | |
238 WmIpc::Message msg(WM_IPC_MESSAGE_WM_NOTIFY_PANEL_DRAG_COMPLETE); | |
239 msg.set_param(0, panel_xid_); | |
240 WmIpc::instance()->SendMessage(msg); | |
241 dragging_ = false; | |
242 } | |
243 } | |
244 | |
245 void PanelController::SetState(State state) { | |
246 WmIpc::Message msg(WM_IPC_MESSAGE_WM_SET_PANEL_STATE); | |
247 msg.set_param(0, panel_xid_); | |
248 msg.set_param(1, state == EXPANDED); | |
249 WmIpc::instance()->SendMessage(msg); | |
250 } | |
251 | |
255 // static | 252 // static |
256 bool PanelController::OnPanelClientEvent( | 253 bool PanelController::OnPanelClientEvent( |
257 GtkWidget* widget, | 254 GtkWidget* widget, |
258 GdkEventClient* event, | 255 GdkEventClient* event, |
259 PanelController* panel_controller) { | 256 PanelController* panel_controller) { |
260 return panel_controller->PanelClientEvent(event); | 257 return panel_controller->PanelClientEvent(event); |
261 } | 258 } |
262 | 259 |
263 void PanelController::OnFocusIn() { | 260 void PanelController::OnFocusIn() { |
264 if (title_window_) | 261 if (title_window_) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 title_label_ = new views::Label(std::wstring()); | 329 title_label_ = new views::Label(std::wstring()); |
333 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 330 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
334 AddChildView(title_label_); | 331 AddChildView(title_label_); |
335 | 332 |
336 set_background( | 333 set_background( |
337 views::Background::CreateBackgroundPainter( | 334 views::Background::CreateBackgroundPainter( |
338 true, new TitleBackgroundPainter())); | 335 true, new TitleBackgroundPainter())); |
339 OnFocusOut(); | 336 OnFocusOut(); |
340 } | 337 } |
341 | 338 |
339 void PanelController::TitleContentView::OnFocusIn() { | |
340 title_label_->SetColor(kTitleActiveColor); | |
341 title_label_->SetFont(*active_font); | |
342 Layout(); | |
343 SchedulePaint(); | |
344 } | |
345 | |
346 void PanelController::TitleContentView::OnFocusOut() { | |
347 title_label_->SetColor(kTitleInactiveColor); | |
348 title_label_->SetFont(*inactive_font); | |
349 Layout(); | |
350 SchedulePaint(); | |
351 } | |
352 | |
353 void PanelController::TitleContentView::OnClose() { | |
354 panel_controller_ = NULL; | |
355 } | |
356 | |
342 void PanelController::TitleContentView::Layout() { | 357 void PanelController::TitleContentView::Layout() { |
343 int close_button_x = bounds().width() - | 358 int close_button_x = bounds().width() - |
344 (close_button_width + kTitleCloseButtonPad); | 359 (close_button_width + kTitleCloseButtonPad); |
345 close_button_->SetBounds( | 360 close_button_->SetBounds( |
346 close_button_x, | 361 close_button_x, |
347 (bounds().height() - close_button_height) / 2, | 362 (bounds().height() - close_button_height) / 2, |
348 close_button_width, | 363 close_button_width, |
349 close_button_height); | 364 close_button_height); |
350 title_icon_->SetBounds( | 365 title_icon_->SetBounds( |
351 kTitleWidthPad, | 366 kTitleWidthPad, |
352 kTitleHeightPad, | 367 kTitleHeightPad, |
353 kTitleIconSize, | 368 kTitleIconSize, |
354 kTitleIconSize); | 369 kTitleIconSize); |
355 int title_x = kTitleWidthPad * 2 + kTitleIconSize; | 370 int title_x = kTitleWidthPad * 2 + kTitleIconSize; |
356 title_label_->SetBounds( | 371 title_label_->SetBounds( |
357 title_x, | 372 title_x, |
358 0, | 373 0, |
359 close_button_x - (title_x + kTitleCloseButtonPad), | 374 close_button_x - (title_x + kTitleCloseButtonPad), |
360 bounds().height()); | 375 bounds().height()); |
361 } | 376 } |
362 | 377 |
363 bool PanelController::TitleContentView::OnMousePressed( | 378 bool PanelController::TitleContentView::OnMousePressed( |
364 const views::MouseEvent& event) { | 379 const views::MouseEvent& event) { |
365 DCHECK(panel_controller_) << "OnMousePressed after Close"; | 380 DCHECK(panel_controller_) << "OnMousePressed after Close"; |
366 return panel_controller_->TitleMousePressed(event); | 381 return panel_controller_->TitleMousePressed(event); |
367 } | 382 } |
368 | 383 |
369 void PanelController::TitleContentView::OnMouseReleased( | |
370 const views::MouseEvent& event, bool canceled) { | |
371 DCHECK(panel_controller_) << "MouseReleased after Close"; | |
372 return panel_controller_->TitleMouseReleased(event, canceled); | |
373 } | |
374 | |
375 bool PanelController::TitleContentView::OnMouseDragged( | 384 bool PanelController::TitleContentView::OnMouseDragged( |
376 const views::MouseEvent& event) { | 385 const views::MouseEvent& event) { |
377 DCHECK(panel_controller_) << "MouseDragged after Close"; | 386 DCHECK(panel_controller_) << "MouseDragged after Close"; |
378 return panel_controller_->TitleMouseDragged(event); | 387 return panel_controller_->TitleMouseDragged(event); |
379 } | 388 } |
380 | 389 |
381 void PanelController::TitleContentView::OnFocusIn() { | 390 void PanelController::TitleContentView::OnMouseReleased( |
382 title_label_->SetColor(kTitleActiveColor); | 391 const views::MouseEvent& event) { |
383 title_label_->SetFont(*active_font); | 392 DCHECK(panel_controller_) << "MouseReleased after Close"; |
384 Layout(); | 393 return panel_controller_->TitleMouseReleased(event); |
385 SchedulePaint(); | |
386 } | 394 } |
387 | 395 |
388 void PanelController::TitleContentView::OnFocusOut() { | 396 void PanelController::TitleContentView::OnMouseCaptureLost() { |
389 title_label_->SetColor(kTitleInactiveColor); | 397 DCHECK(panel_controller_) << "OnMouseCaptureLost after Close"; |
Ben Goodger (Google)
2011/03/19 15:32:55
These kind of DCHECKs are unnecessary. You're goin
msw
2011/03/26 00:09:50
Done. Fixed this file and double-checked my other
| |
390 title_label_->SetFont(*inactive_font); | 398 return panel_controller_->TitleMouseCaptureLost(); |
391 Layout(); | |
392 SchedulePaint(); | |
393 } | |
394 | |
395 void PanelController::TitleContentView::OnClose() { | |
396 panel_controller_ = NULL; | |
397 } | 399 } |
398 | 400 |
399 void PanelController::TitleContentView::ButtonPressed( | 401 void PanelController::TitleContentView::ButtonPressed( |
400 views::Button* sender, const views::Event& event) { | 402 views::Button* sender, const views::Event& event) { |
401 if (panel_controller_ && sender == close_button_) | 403 if (panel_controller_ && sender == close_button_) |
402 panel_controller_->OnCloseButtonPressed(); | 404 panel_controller_->OnCloseButtonPressed(); |
403 } | 405 } |
404 | 406 |
405 PanelController::TitleContentView::~TitleContentView() { | 407 PanelController::TitleContentView::~TitleContentView() { |
406 VLOG(1) << "panel: delete " << this; | 408 VLOG(1) << "panel: delete " << this; |
407 } | 409 } |
408 | 410 |
409 } // namespace chromeos | 411 } // namespace chromeos |
OLD | NEW |