Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/native_window_notification_source.h" | 9 #include "chrome/browser/native_window_notification_source.h" |
| 10 #include "chrome/browser/ui/panels/display_settings_provider.h" | 10 #include "chrome/browser/ui/panels/display_settings_provider.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
| 23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 24 | 24 |
| 25 #if defined(OS_WIN) && !defined(USE_AURA) | 25 #if defined(OS_WIN) && !defined(USE_AURA) |
| 26 #include "base/win/win_util.h" // for IsCtrlPressed() | 26 #include "base/win/win_util.h" // for IsCtrlPressed() |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 using content::WebContents; | 29 using content::WebContents; |
| 30 | 30 |
| 31 namespace { | |
| 32 // The threshold to differentiate the short click and long click. | |
| 33 const int kShortClickThresholdMs = 200; | |
| 34 | |
| 35 // Delay before click-to-minimize is allowed after the attention has been | |
| 36 // cleared. | |
| 37 const int kSuspendMinimizeOnClickIntervalMs = 500; | |
| 38 } | |
| 39 | |
| 40 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, | 31 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
| 41 const gfx::Rect& bounds) { | 32 const gfx::Rect& bounds) { |
| 42 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); | 33 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); |
| 43 (new BrowserFrame(view))->InitBrowserFrame(); | 34 (new BrowserFrame(view))->InitBrowserFrame(); |
| 44 return view; | 35 return view; |
| 45 } | 36 } |
| 46 | 37 |
| 47 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, | 38 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, |
| 48 const gfx::Rect& bounds) | 39 const gfx::Rect& bounds) |
| 49 : BrowserView(browser), | 40 : BrowserView(browser), |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); | 171 GetFrameView()->GetWidget()->GetNativeView() == ::GetForegroundWindow(); |
| 181 #else | 172 #else |
| 182 NOTIMPLEMENTED(); | 173 NOTIMPLEMENTED(); |
| 183 bool focused = active; | 174 bool focused = active; |
| 184 #endif | 175 #endif |
| 185 | 176 |
| 186 if (focused_ == focused) | 177 if (focused_ == focused) |
| 187 return; | 178 return; |
| 188 focused_ = focused; | 179 focused_ = focused; |
| 189 | 180 |
| 190 if (focused_) { | 181 panel()->OnActiveStateChanged(focused); |
| 191 // Expand the panel if needed. Do NOT expand a TITLE_ONLY panel | |
| 192 // otherwise it will be impossible to drag a title without | |
| 193 // expanding it. | |
| 194 if (panel_->expansion_state() == Panel::MINIMIZED) | |
| 195 panel_->SetExpansionState(Panel::EXPANDED); | |
| 196 | |
| 197 if (is_drawing_attention_) { | |
| 198 panel_->FlashFrame(false); | |
| 199 | |
| 200 // Restore the panel from title-only mode here. Could not do this in the | |
| 201 // code above. | |
| 202 if (panel_->expansion_state() == Panel::TITLE_ONLY) | |
| 203 panel_->SetExpansionState(Panel::EXPANDED); | |
| 204 | |
| 205 // This function is called per one of the following user interactions: | |
| 206 // 1) clicking on the title-bar | |
| 207 // 2) clicking on the client area | |
| 208 // 3) switching to the panel via keyboard | |
| 209 // For case 1, we do not want the expanded panel to be minimized since the | |
| 210 // user clicks on it to mean to clear the attention. | |
| 211 attention_cleared_time_ = base::TimeTicks::Now(); | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 content::NotificationService::current()->Notify( | |
| 216 chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, | |
| 217 content::Source<Panel>(panel()), | |
| 218 content::NotificationService::NoDetails()); | |
| 219 panel()->OnActiveStateChanged(); | |
| 220 } | 182 } |
| 221 | 183 |
| 222 bool PanelBrowserView::AcceleratorPressed( | 184 bool PanelBrowserView::AcceleratorPressed( |
| 223 const ui::Accelerator& accelerator) { | 185 const ui::Accelerator& accelerator) { |
| 224 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { | 186 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { |
| 225 OnTitlebarMouseCaptureLost(); | 187 OnTitlebarMouseCaptureLost(); |
| 226 return true; | 188 return true; |
| 227 } | 189 } |
| 228 | 190 |
| 229 // No other accelerator is allowed when the drag begins. | 191 // No other accelerator is allowed when the drag begins. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 panel_->manager()->Drag(mouse_location); | 468 panel_->manager()->Drag(mouse_location); |
| 507 | 469 |
| 508 // Once in drag, update |last_mouse_location_| on each drag fragment, since | 470 // Once in drag, update |last_mouse_location_| on each drag fragment, since |
| 509 // we already dragged the panel up to the current mouse location. | 471 // we already dragged the panel up to the current mouse location. |
| 510 last_mouse_location_ = mouse_location; | 472 last_mouse_location_ = mouse_location; |
| 511 } | 473 } |
| 512 return true; | 474 return true; |
| 513 } | 475 } |
| 514 | 476 |
| 515 bool PanelBrowserView::OnTitlebarMouseReleased() { | 477 bool PanelBrowserView::OnTitlebarMouseReleased() { |
| 516 if (mouse_dragging_state_ == DRAGGING_STARTED) { | 478 if (mouse_dragging_state_ != NO_DRAGGING) { |
| 517 // When a drag ends, restore the focus. | 479 // Ensure dragging a minimized panel does not leave it activated. |
| 518 if (old_focused_view_) { | 480 // Windows activates a panel on mouse-down, regardless of our attempts |
| 519 GetFocusManager()->SetFocusedView(old_focused_view_); | 481 // to prevent activation of a minimized panel. Now that we know mouse-down |
| 520 old_focused_view_ = NULL; | 482 // resulted in a mouse-drag, we need to ensure the minimized panel is |
| 483 // deactivated. | |
| 484 if (panel_->IsMinimized() && panel_->IsActive()) | |
| 485 panel_->Deactivate(); | |
|
jianli
2012/04/25 18:19:31
It might be better if we can figure out a way to a
jennb
2012/04/25 20:34:05
crbug created instead.
| |
| 486 | |
| 487 if (mouse_dragging_state_ == DRAGGING_STARTED) { | |
| 488 // When a drag ends, restore the focus. | |
| 489 if (old_focused_view_) { | |
| 490 GetFocusManager()->SetFocusedView(old_focused_view_); | |
| 491 old_focused_view_ = NULL; | |
| 492 } | |
| 493 return EndDragging(false); | |
| 521 } | 494 } |
| 522 | 495 |
| 523 return EndDragging(false); | 496 // Else, the panel drag was cancelled before the mouse is released. Do not |
| 497 // treat this as a click. | |
| 498 if (mouse_dragging_state_ != NO_DRAGGING) | |
| 499 return true; | |
| 524 } | 500 } |
| 525 | 501 |
| 526 // If the panel drag was cancelled before the mouse is released, do not treat | 502 panel::ClickModifier click_modifier = panel::NO_MODIFIER; |
| 527 // this as a click. | |
| 528 if (mouse_dragging_state_ != NO_DRAGGING) | |
| 529 return true; | |
| 530 | |
| 531 // Ignore long clicks. Treated as a canceled click to be consistent with Mac. | |
| 532 if (base::TimeTicks::Now() - mouse_pressed_time_ > | |
| 533 base::TimeDelta::FromMilliseconds(kShortClickThresholdMs)) | |
| 534 return true; | |
| 535 | |
| 536 #if defined(OS_WIN) && !defined(USE_AURA) | 503 #if defined(OS_WIN) && !defined(USE_AURA) |
| 537 if (base::win::IsCtrlPressed()) { | 504 if (base::win::IsCtrlPressed()) { |
| 538 panel_->OnTitlebarClicked(panel::APPLY_TO_ALL); | 505 click_modifier = panel::APPLY_TO_ALL; |
| 539 return true; | |
| 540 } | 506 } |
| 541 #else | 507 #else |
| 542 NOTIMPLEMENTED(); // Proceed without modifier. | 508 // Proceed without modifier. |
| 543 #endif | 509 #endif |
| 544 | 510 |
| 545 // TODO(jennb): Move remaining titlebar click handling out of here. | 511 panel_->OnTitlebarClicked(click_modifier); |
| 546 // (http://crbug.com/118431) | |
| 547 PanelStrip* panel_strip = panel_->panel_strip(); | |
| 548 if (!panel_strip) | |
| 549 return true; | |
| 550 | |
| 551 // Do not minimize the panel when we just clear the attention state. This is | |
| 552 // a hack to prevent the panel from being minimized when the user clicks on | |
| 553 // the title-bar to clear the attention. | |
| 554 if (panel_strip->type() == PanelStrip::DOCKED && | |
| 555 panel_->expansion_state() == Panel::EXPANDED && | |
| 556 base::TimeTicks::Now() - attention_cleared_time_ < | |
| 557 base::TimeDelta::FromMilliseconds(kSuspendMinimizeOnClickIntervalMs)) { | |
| 558 return true; | |
| 559 } | |
| 560 | |
| 561 if (panel_strip->type() == PanelStrip::DOCKED && | |
| 562 panel_->expansion_state() == Panel::EXPANDED) | |
| 563 panel_->SetExpansionState(Panel::MINIMIZED); | |
| 564 else | |
| 565 panel_->Activate(); | |
| 566 | |
| 567 return true; | 512 return true; |
| 568 } | 513 } |
| 569 | 514 |
| 570 bool PanelBrowserView::OnTitlebarMouseCaptureLost() { | 515 bool PanelBrowserView::OnTitlebarMouseCaptureLost() { |
| 571 if (mouse_dragging_state_ == DRAGGING_STARTED) | 516 if (mouse_dragging_state_ == DRAGGING_STARTED) |
| 572 return EndDragging(true); | 517 return EndDragging(true); |
| 573 return true; | 518 return true; |
| 574 } | 519 } |
| 575 | 520 |
| 576 bool PanelBrowserView::EndDragging(bool cancelled) { | 521 bool PanelBrowserView::EndDragging(bool cancelled) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 return expected_color == frame_view->title_label_->enabled_color(); | 685 return expected_color == frame_view->title_label_->enabled_color(); |
| 741 } | 686 } |
| 742 | 687 |
| 743 bool NativePanelTestingWin::IsWindowSizeKnown() const { | 688 bool NativePanelTestingWin::IsWindowSizeKnown() const { |
| 744 return true; | 689 return true; |
| 745 } | 690 } |
| 746 | 691 |
| 747 bool NativePanelTestingWin::IsAnimatingBounds() const { | 692 bool NativePanelTestingWin::IsAnimatingBounds() const { |
| 748 return panel_browser_view_->IsAnimatingBounds(); | 693 return panel_browser_view_->IsAnimatingBounds(); |
| 749 } | 694 } |
| OLD | NEW |