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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/ui/panels/panel.h" | 9 #include "chrome/browser/ui/panels/panel.h" |
10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" | 10 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
11 #include "chrome/browser/ui/panels/panel_manager.h" | 11 #include "chrome/browser/ui/panels/panel_manager.h" |
| 12 #include "chrome/browser/ui/panels/panel_overflow_strip.h" |
| 13 #include "chrome/browser/ui/panels/panel_strip.h" |
12 #include "chrome/browser/ui/views/frame/browser_frame.h" | 14 #include "chrome/browser/ui/views/frame/browser_frame.h" |
13 #include "chrome/browser/ui/webui/task_manager_dialog.h" | 15 #include "chrome/browser/ui/webui/task_manager_dialog.h" |
14 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
16 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
17 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
18 #include "ui/base/animation/slide_animation.h" | 20 #include "ui/base/animation/slide_animation.h" |
19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
21 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 109 } |
108 | 110 |
109 bool PanelBrowserView::CanMaximize() const { | 111 bool PanelBrowserView::CanMaximize() const { |
110 return false; | 112 return false; |
111 } | 113 } |
112 | 114 |
113 void PanelBrowserView::SetBounds(const gfx::Rect& bounds) { | 115 void PanelBrowserView::SetBounds(const gfx::Rect& bounds) { |
114 SetBoundsInternal(bounds, true); | 116 SetBoundsInternal(bounds, true); |
115 } | 117 } |
116 | 118 |
117 void PanelBrowserView::SetBoundsInternal(const gfx::Rect& bounds, | 119 void PanelBrowserView::SetBoundsInternal(const gfx::Rect& new_bounds, |
118 bool animate) { | 120 bool animate) { |
119 if (bounds_ == bounds) | 121 if (bounds_ == new_bounds) |
120 return; | 122 return; |
121 bounds_ = bounds; | 123 |
| 124 // TODO(jianli): this is just a temporary hack to check if we need to show |
| 125 // or hide the panel app icon in the taskbar. http://crbug.com/106227 |
| 126 int panel_strip_area_left = |
| 127 panel()->manager()->panel_strip()->display_area().x(); |
| 128 bool app_icon_shown = bounds_.x() >= panel_strip_area_left; |
| 129 bool app_icon_to_show = new_bounds.x() >= panel_strip_area_left; |
| 130 if (app_icon_shown != app_icon_to_show) |
| 131 ShowOrHidePanelAppIcon(app_icon_to_show); |
| 132 |
| 133 bounds_ = new_bounds; |
122 | 134 |
123 // No animation if the panel is being dragged. | 135 // No animation if the panel is being dragged. |
124 if (!animate || mouse_dragging_state_ == DRAGGING_STARTED) { | 136 if (!animate || mouse_dragging_state_ == DRAGGING_STARTED) { |
125 ::BrowserView::SetBounds(bounds); | 137 ::BrowserView::SetBounds(new_bounds); |
126 return; | 138 return; |
127 } | 139 } |
128 | 140 |
129 animation_start_bounds_ = GetBounds(); | 141 animation_start_bounds_ = GetBounds(); |
130 | 142 |
131 if (!bounds_animator_.get()) { | 143 if (!bounds_animator_.get()) { |
132 bounds_animator_.reset(new ui::SlideAnimation(this)); | 144 bounds_animator_.reset(new ui::SlideAnimation(this)); |
133 bounds_animator_->SetSlideDuration(kSetBoundsAnimationMs); | 145 bounds_animator_->SetSlideDuration(kSetBoundsAnimationMs); |
134 } | 146 } |
135 | 147 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 403 |
392 Browser* PanelBrowserView::GetPanelBrowser() const { | 404 Browser* PanelBrowserView::GetPanelBrowser() const { |
393 return browser(); | 405 return browser(); |
394 } | 406 } |
395 | 407 |
396 void PanelBrowserView::DestroyPanelBrowser() { | 408 void PanelBrowserView::DestroyPanelBrowser() { |
397 DestroyBrowser(); | 409 DestroyBrowser(); |
398 } | 410 } |
399 | 411 |
400 gfx::Size PanelBrowserView::IconOnlySize() const { | 412 gfx::Size PanelBrowserView::IconOnlySize() const { |
401 // TODO(jianli): to be implemented. | 413 return GetFrameView()->IconOnlySize(); |
402 return gfx::Size(); | |
403 } | 414 } |
404 | 415 |
405 void PanelBrowserView::EnsurePanelFullyVisible() { | 416 void PanelBrowserView::EnsurePanelFullyVisible() { |
406 // TODO(jianli): to be implemented. | 417 #if defined(OS_WIN) && !defined(USE_AURA) |
| 418 ::SetWindowPos(GetNativeHandle(), HWND_TOP, 0, 0, 0, 0, |
| 419 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); |
| 420 #else |
| 421 NOTIMPLEMENTED(); |
| 422 #endif |
407 } | 423 } |
408 | 424 |
409 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { | 425 PanelBrowserFrameView* PanelBrowserView::GetFrameView() const { |
410 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); | 426 return static_cast<PanelBrowserFrameView*>(frame()->GetFrameView()); |
411 } | 427 } |
412 | 428 |
413 bool PanelBrowserView::OnTitlebarMousePressed(const gfx::Point& location) { | 429 bool PanelBrowserView::OnTitlebarMousePressed(const gfx::Point& location) { |
414 // |location| is in the view's coordinate system. Convert it to the screen | 430 // |location| is in the view's coordinate system. Convert it to the screen |
415 // coordinate system. | 431 // coordinate system. |
416 mouse_location_ = location; | 432 mouse_location_ = location; |
417 views::View::ConvertPointToScreen(this, &mouse_location_); | 433 views::View::ConvertPointToScreen(this, &mouse_location_); |
418 | 434 |
419 mouse_pressed_ = true; | 435 mouse_pressed_ = true; |
420 mouse_pressed_time_ = base::TimeTicks::Now(); | 436 mouse_pressed_time_ = base::TimeTicks::Now(); |
421 mouse_dragging_state_ = NO_DRAGGING; | 437 mouse_dragging_state_ = NO_DRAGGING; |
422 return true; | 438 return true; |
423 } | 439 } |
424 | 440 |
425 bool PanelBrowserView::OnTitlebarMouseDragged(const gfx::Point& location) { | 441 bool PanelBrowserView::OnTitlebarMouseDragged(const gfx::Point& location) { |
426 if (!mouse_pressed_) | 442 if (!mouse_pressed_) |
427 return false; | 443 return false; |
428 | 444 |
| 445 // Dragging is not supported for overflow panel. |
| 446 if (panel_->expansion_state() == Panel::IN_OVERFLOW) |
| 447 return true; |
| 448 |
429 gfx::Point last_mouse_location = mouse_location_; | 449 gfx::Point last_mouse_location = mouse_location_; |
430 | 450 |
431 // |location| is in the view's coordinate system. Convert it to the screen | 451 // |location| is in the view's coordinate system. Convert it to the screen |
432 // coordinate system. | 452 // coordinate system. |
433 mouse_location_ = location; | 453 mouse_location_ = location; |
434 views::View::ConvertPointToScreen(this, &mouse_location_); | 454 views::View::ConvertPointToScreen(this, &mouse_location_); |
435 | 455 |
436 int delta_x = mouse_location_.x() - last_mouse_location.x(); | 456 int delta_x = mouse_location_.x() - last_mouse_location.x(); |
437 int delta_y = mouse_location_.y() - last_mouse_location.y(); | 457 int delta_y = mouse_location_.y() - last_mouse_location.y(); |
438 if (mouse_dragging_state_ == NO_DRAGGING && | 458 if (mouse_dragging_state_ == NO_DRAGGING && |
(...skipping 20 matching lines...) Expand all Loading... |
459 } | 479 } |
460 | 480 |
461 return EndDragging(false); | 481 return EndDragging(false); |
462 } | 482 } |
463 | 483 |
464 // If the panel drag was cancelled before the mouse is released, do not treat | 484 // If the panel drag was cancelled before the mouse is released, do not treat |
465 // this as a click. | 485 // this as a click. |
466 if (mouse_dragging_state_ != NO_DRAGGING) | 486 if (mouse_dragging_state_ != NO_DRAGGING) |
467 return true; | 487 return true; |
468 | 488 |
| 489 // If the panel is in overflow, move it to the normal strip. |
| 490 if (panel_->expansion_state() == Panel::IN_OVERFLOW) { |
| 491 panel_->MoveOutOfOverflow(); |
| 492 return true; |
| 493 } |
| 494 |
469 // Do not minimize the panel when we just clear the attention state. This is | 495 // Do not minimize the panel when we just clear the attention state. This is |
470 // a hack to prevent the panel from being minimized when the user clicks on | 496 // a hack to prevent the panel from being minimized when the user clicks on |
471 // the title-bar to clear the attention. | 497 // the title-bar to clear the attention. |
472 if (panel_->expansion_state() == Panel::EXPANDED && | 498 if (panel_->expansion_state() == Panel::EXPANDED && |
473 base::TimeTicks::Now() - attention_cleared_time_ < | 499 base::TimeTicks::Now() - attention_cleared_time_ < |
474 base::TimeDelta::FromMilliseconds(kSuspendMinimizeOnClickIntervalMs)) { | 500 base::TimeDelta::FromMilliseconds(kSuspendMinimizeOnClickIntervalMs)) { |
475 return true; | 501 return true; |
476 } | 502 } |
477 | 503 |
478 // Do not minimize the panel if it is long click. | 504 // Do not minimize the panel if it is long click. |
(...skipping 18 matching lines...) Expand all Loading... |
497 // Only handle clicks that started in our window. | 523 // Only handle clicks that started in our window. |
498 if (!mouse_pressed_) | 524 if (!mouse_pressed_) |
499 return false; | 525 return false; |
500 mouse_pressed_ = false; | 526 mouse_pressed_ = false; |
501 | 527 |
502 mouse_dragging_state_ = DRAGGING_ENDED; | 528 mouse_dragging_state_ = DRAGGING_ENDED; |
503 panel_->manager()->EndDragging(cancelled); | 529 panel_->manager()->EndDragging(cancelled); |
504 return true; | 530 return true; |
505 } | 531 } |
506 | 532 |
| 533 void PanelBrowserView::ShowOrHidePanelAppIcon(bool show) { |
| 534 #if defined(OS_WIN) && !defined(USE_AURA) |
| 535 gfx::NativeWindow native_window = GetNativeHandle(); |
| 536 ::ShowWindow(native_window, SW_HIDE); |
| 537 int style = ::GetWindowLong(native_window, GWL_EXSTYLE); |
| 538 if (show) |
| 539 style &= (~WS_EX_TOOLWINDOW); |
| 540 else |
| 541 style |= WS_EX_TOOLWINDOW; |
| 542 ::SetWindowLong(native_window, GWL_EXSTYLE, style); |
| 543 ::ShowWindow(native_window, SW_SHOWNA); |
| 544 #else |
| 545 NOTIMPLEMENTED(); |
| 546 #endif |
| 547 } |
| 548 |
507 // NativePanelTesting implementation. | 549 // NativePanelTesting implementation. |
508 class NativePanelTestingWin : public NativePanelTesting { | 550 class NativePanelTestingWin : public NativePanelTesting { |
509 public: | 551 public: |
510 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); | 552 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); |
511 | 553 |
512 private: | 554 private: |
513 virtual void PressLeftMouseButtonTitlebar( | 555 virtual void PressLeftMouseButtonTitlebar( |
514 const gfx::Point& point) OVERRIDE; | 556 const gfx::Point& point) OVERRIDE; |
515 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; | 557 virtual void ReleaseMouseButtonTitlebar() OVERRIDE; |
516 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; | 558 virtual void DragTitlebar(int delta_x, int delta_y) OVERRIDE; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 } | 628 } |
587 | 629 |
588 bool NativePanelTestingWin::IsWindowSizeKnown() const { | 630 bool NativePanelTestingWin::IsWindowSizeKnown() const { |
589 return true; | 631 return true; |
590 } | 632 } |
591 | 633 |
592 bool NativePanelTestingWin::IsAnimatingBounds() const { | 634 bool NativePanelTestingWin::IsAnimatingBounds() const { |
593 return panel_browser_view_->bounds_animator_.get() && | 635 return panel_browser_view_->bounds_animator_.get() && |
594 panel_browser_view_->bounds_animator_->is_animating(); | 636 panel_browser_view_->bounds_animator_->is_animating(); |
595 } | 637 } |
OLD | NEW |