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/ui/panels/panel_browser_view.h" | 5 #include "chrome/browser/ui/panels/panel_browser_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/ui/panels/panel.h" | 8 #include "chrome/browser/ui/panels/panel.h" |
9 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" | 9 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
10 #include "chrome/browser/ui/panels/panel_manager.h" | 10 #include "chrome/browser/ui/panels/panel_manager.h" |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 } | 302 } |
303 | 303 |
304 Browser* PanelBrowserView::GetPanelBrowser() const { | 304 Browser* PanelBrowserView::GetPanelBrowser() const { |
305 return browser(); | 305 return browser(); |
306 } | 306 } |
307 | 307 |
308 void PanelBrowserView::DestroyPanelBrowser() { | 308 void PanelBrowserView::DestroyPanelBrowser() { |
309 DestroyBrowser(); | 309 DestroyBrowser(); |
310 } | 310 } |
311 | 311 |
312 NativePanelTesting* PanelBrowserView::GetNativePanelTesting() { | |
313 return this; | |
314 } | |
315 | |
316 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { | 312 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { |
317 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); | 313 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); |
318 } | 314 } |
319 | 315 |
320 bool PanelBrowserView::OnTitleBarMousePressed(const views::MouseEvent& event) { | 316 bool PanelBrowserView::OnTitleBarMousePressed(const gfx::Point& location) { |
321 if (!event.IsOnlyLeftMouseButton()) | |
322 return false; | |
323 mouse_pressed_ = true; | 317 mouse_pressed_ = true; |
324 mouse_pressed_point_ = event.location(); | 318 mouse_pressed_point_ = location; |
325 mouse_dragging_ = false; | 319 mouse_dragging_ = false; |
326 return true; | 320 return true; |
327 } | 321 } |
328 | 322 |
329 bool PanelBrowserView::OnTitleBarMouseDragged(const views::MouseEvent& event) { | 323 bool PanelBrowserView::OnTitleBarMouseDragged(const gfx::Point& location) { |
330 if (!mouse_pressed_) | 324 if (!mouse_pressed_) |
331 return false; | 325 return false; |
332 | 326 |
333 // We do not allow dragging vertically. | 327 // We do not allow dragging vertically. |
334 int delta_x = event.location().x() - mouse_pressed_point_.x(); | 328 int delta_x = location.x() - mouse_pressed_point_.x(); |
335 if (!mouse_dragging_ && ExceededDragThreshold(delta_x, 0)) { | 329 if (!mouse_dragging_ && ExceededDragThreshold(delta_x, 0)) { |
336 panel_->manager()->StartDragging(panel_.get()); | 330 panel_->manager()->StartDragging(panel_.get()); |
337 mouse_dragging_ = true; | 331 mouse_dragging_ = true; |
338 } | 332 } |
339 if (mouse_dragging_) | 333 if (mouse_dragging_) |
340 panel_->manager()->Drag(delta_x); | 334 panel_->manager()->Drag(delta_x); |
341 return true; | 335 return true; |
342 } | 336 } |
343 | 337 |
344 bool PanelBrowserView::OnTitleBarMouseReleased(const views::MouseEvent& event) { | 338 bool PanelBrowserView::OnTitleBarMouseReleased() { |
345 if (mouse_dragging_) | 339 if (mouse_dragging_) |
346 return EndDragging(false); | 340 return EndDragging(false); |
347 | 341 |
348 // Do not minimize the panel when we just clear the attention state. This is | 342 // Do not minimize the panel when we just clear the attention state. This is |
349 // a hack to prevent the panel from being minimized when the user clicks on | 343 // a hack to prevent the panel from being minimized when the user clicks on |
350 // the title-bar to clear the attention. | 344 // the title-bar to clear the attention. |
351 if (panel_->expansion_state() == Panel::EXPANDED && | 345 if (panel_->expansion_state() == Panel::EXPANDED && |
352 base::TimeTicks::Now() < attention_cleared_time_ + | 346 base::TimeTicks::Now() < attention_cleared_time_ + |
353 kSuspendMinimizeOnClickIntervalMs) { | 347 kSuspendMinimizeOnClickIntervalMs) { |
354 return true; | 348 return true; |
(...skipping 15 matching lines...) Expand all Loading... | |
370 if (!mouse_pressed_) | 364 if (!mouse_pressed_) |
371 return false; | 365 return false; |
372 mouse_pressed_ = false; | 366 mouse_pressed_ = false; |
373 | 367 |
374 if (!mouse_dragging_) | 368 if (!mouse_dragging_) |
375 cancelled = true; | 369 cancelled = true; |
376 mouse_dragging_ = false; | 370 mouse_dragging_ = false; |
377 panel_->manager()->EndDragging(cancelled); | 371 panel_->manager()->EndDragging(cancelled); |
378 return true; | 372 return true; |
379 } | 373 } |
374 | |
375 // NativePanelTesting implementation. | |
376 class NativePanelTestingWin : public NativePanelTesting { | |
jianli
2011/08/11 20:52:09
Please move this subclass to the anonymous namespa
prasadt
2011/08/11 21:07:56
Need this class in header file.
| |
377 public: | |
378 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); | |
379 | |
380 private: | |
381 virtual void PressLeftMouseButtonTitlebar( | |
382 const gfx::Point& point) OVERRIDE; | |
383 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; | |
384 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; | |
385 virtual void CancelDragTitlebar() OVERRIDE; | |
386 virtual void FinishDragTitlebar() OVERRIDE; | |
387 | |
388 PanelBrowserView* panel_browser_view_; | |
389 }; | |
390 | |
391 NativePanelTesting* NativePanelTesting::Create(NativePanel* native_panel) { | |
jianli
2011/08/11 20:52:09
Please add the comment like the following:
// st
prasadt
2011/08/11 21:07:56
Done.
| |
392 return new NativePanelTestingWin(static_cast<PanelBrowserView*>( | |
393 native_panel)); | |
394 } | |
395 | |
396 NativePanelTestingWin::NativePanelTestingWin( | |
397 PanelBrowserView* panel_browser_view) : | |
398 panel_browser_view_(panel_browser_view) { | |
399 } | |
400 | |
401 void NativePanelTestingWin::PressLeftMouseButtonTitlebar( | |
402 const gfx::Point& point) { | |
403 panel_browser_view_->OnTitleBarMousePressed(point); | |
404 } | |
405 | |
406 void NativePanelTestingWin::ReleaseMouseButtonTitlebar() { | |
407 panel_browser_view_->OnTitleBarMouseReleased(); | |
408 } | |
409 | |
410 void NativePanelTestingWin::DragTitlebar(int delta_x, int delta_y) { | |
411 gfx::Rect current_bounds = panel_browser_view_->panel()->GetRestoredBounds(); | |
412 panel_browser_view_->OnTitleBarMouseDragged(gfx::Point( | |
413 current_bounds.x() + delta_x, current_bounds.y() + delta_y)); | |
414 } | |
415 | |
416 void NativePanelTestingWin::CancelDragTitlebar() { | |
417 panel_browser_view_->OnTitleBarMouseCaptureLost(); | |
418 } | |
419 | |
420 void NativePanelTestingWin::FinishDragTitlebar() { | |
421 panel_browser_view_->OnTitleBarMouseReleased(); | |
422 } | |
OLD | NEW |