| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 title_content_ = new TitleContentView(this); | 152 title_content_ = new TitleContentView(this); |
| 153 title_window_->SetContentsView(title_content_); | 153 title_window_->SetContentsView(title_content_); |
| 154 UpdateTitleBar(); | 154 UpdateTitleBar(); |
| 155 title_window_->Show(); | 155 title_window_->Show(); |
| 156 } | 156 } |
| 157 | 157 |
| 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_); | |
| 162 title_content_->title_label()->SetText( | 161 title_content_->title_label()->SetText( |
| 163 UTF16ToWideHack(delegate_->GetPanelTitle())); | 162 UTF16ToWideHack(delegate_->GetPanelTitle())); |
| 164 title_content_->title_icon()->SetImage(delegate_->GetPanelIcon()); | 163 title_content_->title_icon()->SetImage(delegate_->GetPanelIcon()); |
| 165 } | 164 } |
| 166 | 165 |
| 167 bool PanelController::TitleMousePressed(const views::MouseEvent& event) { | 166 bool PanelController::TitleMousePressed(const views::MouseEvent& event) { |
| 168 if (!event.IsOnlyLeftMouseButton()) { | 167 if (!event.IsOnlyLeftMouseButton()) |
| 169 return false; | 168 return false; |
| 170 } | |
| 171 GdkEvent* gdk_event = gtk_get_current_event(); | 169 GdkEvent* gdk_event = gtk_get_current_event(); |
| 172 if (gdk_event->type != GDK_BUTTON_PRESS) { | 170 if (gdk_event->type != GDK_BUTTON_PRESS) { |
| 173 gdk_event_free(gdk_event); | 171 gdk_event_free(gdk_event); |
| 174 NOTREACHED(); | 172 NOTREACHED(); |
| 175 return false; | 173 return false; |
| 176 } | 174 } |
| 177 DCHECK(title_); | 175 DCHECK(title_); |
| 178 // Get the last titlebar width that we saw in a ConfigureNotify event -- we | 176 // 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 | 177 // 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 | 178 // titlebar window. See WM_IPC_MESSAGE_WM_NOTIFY_PANEL_DRAGGED's declaration |
| 181 // for details. | 179 // for details. |
| 182 gint title_width = 1; | 180 gint title_width = 1; |
| 183 gtk_window_get_size(GTK_WINDOW(title_), &title_width, NULL); | 181 gtk_window_get_size(GTK_WINDOW(title_), &title_width, NULL); |
| 184 | 182 |
| 185 GdkEventButton last_button_event = gdk_event->button; | 183 GdkEventButton last_button_event = gdk_event->button; |
| 186 mouse_down_ = true; | 184 mouse_down_ = true; |
| 187 mouse_down_abs_x_ = last_button_event.x_root; | 185 mouse_down_abs_x_ = last_button_event.x_root; |
| 188 mouse_down_abs_y_ = last_button_event.y_root; | 186 mouse_down_abs_y_ = last_button_event.y_root; |
| 189 mouse_down_offset_x_ = event.x() - title_width; | 187 mouse_down_offset_x_ = event.x() - title_width; |
| 190 mouse_down_offset_y_ = event.y(); | 188 mouse_down_offset_y_ = event.y(); |
| 191 dragging_ = false; | 189 dragging_ = false; |
| 192 gdk_event_free(gdk_event); | 190 gdk_event_free(gdk_event); |
| 193 return true; | 191 return true; |
| 194 } | 192 } |
| 195 | 193 |
| 196 void PanelController::TitleMouseReleased( | 194 void PanelController::TitleMouseReleased(const views::MouseEvent& event) { |
| 197 const views::MouseEvent& event, bool canceled) { | 195 if (event.IsLeftMouseButton()) |
| 198 if (!event.IsLeftMouseButton()) { | 196 TitleMouseCaptureLost(); |
| 197 } |
| 198 |
| 199 void PanelController::TitleMouseCaptureLost() { |
| 200 // Only handle clicks that started in our window. |
| 201 if (!mouse_down_) |
| 199 return; | 202 return; |
| 200 } | |
| 201 // Only handle clicks that started in our window. | |
| 202 if (!mouse_down_) { | |
| 203 return; | |
| 204 } | |
| 205 | 203 |
| 206 mouse_down_ = false; | 204 mouse_down_ = false; |
| 207 if (!dragging_) { | 205 if (!dragging_) { |
| 208 SetState(expanded_ ? | 206 SetState(expanded_ ? |
| 209 PanelController::MINIMIZED : PanelController::EXPANDED); | 207 PanelController::MINIMIZED : PanelController::EXPANDED); |
| 210 } else { | 208 } else { |
| 211 WmIpc::Message msg(WM_IPC_MESSAGE_WM_NOTIFY_PANEL_DRAG_COMPLETE); | 209 WmIpc::Message msg(WM_IPC_MESSAGE_WM_NOTIFY_PANEL_DRAG_COMPLETE); |
| 212 msg.set_param(0, panel_xid_); | 210 msg.set_param(0, panel_xid_); |
| 213 WmIpc::instance()->SendMessage(msg); | 211 WmIpc::instance()->SendMessage(msg); |
| 214 dragging_ = false; | 212 dragging_ = false; |
| 215 } | 213 } |
| 216 } | 214 } |
| 217 | 215 |
| 218 void PanelController::SetState(State state) { | 216 void PanelController::SetState(State state) { |
| 219 WmIpc::Message msg(WM_IPC_MESSAGE_WM_SET_PANEL_STATE); | 217 WmIpc::Message msg(WM_IPC_MESSAGE_WM_SET_PANEL_STATE); |
| 220 msg.set_param(0, panel_xid_); | 218 msg.set_param(0, panel_xid_); |
| 221 msg.set_param(1, state == EXPANDED); | 219 msg.set_param(1, state == EXPANDED); |
| 222 WmIpc::instance()->SendMessage(msg); | 220 WmIpc::instance()->SendMessage(msg); |
| 223 } | 221 } |
| 224 | 222 |
| 225 bool PanelController::TitleMouseDragged(const views::MouseEvent& event) { | 223 bool PanelController::TitleMouseDragged(const views::MouseEvent& event) { |
| 226 if (!mouse_down_) { | 224 if (!mouse_down_) |
| 227 return false; | 225 return false; |
| 228 } | |
| 229 | |
| 230 GdkEvent* gdk_event = gtk_get_current_event(); | 226 GdkEvent* gdk_event = gtk_get_current_event(); |
| 231 if (gdk_event->type != GDK_MOTION_NOTIFY) { | 227 if (gdk_event->type != GDK_MOTION_NOTIFY) { |
| 232 gdk_event_free(gdk_event); | 228 gdk_event_free(gdk_event); |
| 233 NOTREACHED(); | 229 NOTREACHED(); |
| 234 return false; | 230 return false; |
| 235 } | 231 } |
| 236 GdkEventMotion last_motion_event = gdk_event->motion; | 232 GdkEventMotion last_motion_event = gdk_event->motion; |
| 237 if (!dragging_) { | 233 if (!dragging_) { |
| 238 if (views::View::ExceededDragThreshold( | 234 if (views::View::ExceededDragThreshold( |
| 239 last_motion_event.x_root - mouse_down_abs_x_, | 235 last_motion_event.x_root - mouse_down_abs_x_, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 int title_x = kTitleWidthPad * 2 + kTitleIconSize; | 351 int title_x = kTitleWidthPad * 2 + kTitleIconSize; |
| 356 title_label_->SetBounds( | 352 title_label_->SetBounds( |
| 357 title_x, | 353 title_x, |
| 358 0, | 354 0, |
| 359 close_button_x - (title_x + kTitleCloseButtonPad), | 355 close_button_x - (title_x + kTitleCloseButtonPad), |
| 360 bounds().height()); | 356 bounds().height()); |
| 361 } | 357 } |
| 362 | 358 |
| 363 bool PanelController::TitleContentView::OnMousePressed( | 359 bool PanelController::TitleContentView::OnMousePressed( |
| 364 const views::MouseEvent& event) { | 360 const views::MouseEvent& event) { |
| 365 DCHECK(panel_controller_) << "OnMousePressed after Close"; | |
| 366 return panel_controller_->TitleMousePressed(event); | 361 return panel_controller_->TitleMousePressed(event); |
| 367 } | 362 } |
| 368 | 363 |
| 369 void PanelController::TitleContentView::OnMouseReleased( | 364 void PanelController::TitleContentView::OnMouseReleased( |
| 370 const views::MouseEvent& event, bool canceled) { | 365 const views::MouseEvent& event) { |
| 371 DCHECK(panel_controller_) << "MouseReleased after Close"; | 366 panel_controller_->TitleMouseReleased(event); |
| 372 return panel_controller_->TitleMouseReleased(event, canceled); | 367 } |
| 368 |
| 369 void PanelController::TitleContentView::OnMouseCaptureLost() { |
| 370 panel_controller_->TitleMouseCaptureLost(); |
| 373 } | 371 } |
| 374 | 372 |
| 375 bool PanelController::TitleContentView::OnMouseDragged( | 373 bool PanelController::TitleContentView::OnMouseDragged( |
| 376 const views::MouseEvent& event) { | 374 const views::MouseEvent& event) { |
| 377 DCHECK(panel_controller_) << "MouseDragged after Close"; | |
| 378 return panel_controller_->TitleMouseDragged(event); | 375 return panel_controller_->TitleMouseDragged(event); |
| 379 } | 376 } |
| 380 | 377 |
| 381 void PanelController::TitleContentView::OnFocusIn() { | 378 void PanelController::TitleContentView::OnFocusIn() { |
| 382 title_label_->SetColor(kTitleActiveColor); | 379 title_label_->SetColor(kTitleActiveColor); |
| 383 title_label_->SetFont(*active_font); | 380 title_label_->SetFont(*active_font); |
| 384 Layout(); | 381 Layout(); |
| 385 SchedulePaint(); | 382 SchedulePaint(); |
| 386 } | 383 } |
| 387 | 384 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 400 views::Button* sender, const views::Event& event) { | 397 views::Button* sender, const views::Event& event) { |
| 401 if (panel_controller_ && sender == close_button_) | 398 if (panel_controller_ && sender == close_button_) |
| 402 panel_controller_->OnCloseButtonPressed(); | 399 panel_controller_->OnCloseButtonPressed(); |
| 403 } | 400 } |
| 404 | 401 |
| 405 PanelController::TitleContentView::~TitleContentView() { | 402 PanelController::TitleContentView::~TitleContentView() { |
| 406 VLOG(1) << "panel: delete " << this; | 403 VLOG(1) << "panel: delete " << this; |
| 407 } | 404 } |
| 408 | 405 |
| 409 } // namespace chromeos | 406 } // namespace chromeos |
| OLD | NEW |