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 // Do not clear draw attention if user cannot see contents of panel. |
| 191 // Expand the panel if needed. Do NOT expand a TITLE_ONLY panel | 182 if (focused_ && is_drawing_attention_ && !panel_->IsMinimized()) |
| 192 // otherwise it will be impossible to drag a title without | 183 panel_->FlashFrame(false); |
| 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 | 184 |
| 215 content::NotificationService::current()->Notify( | 185 content::NotificationService::current()->Notify( |
| 216 chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, | 186 chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, |
| 217 content::Source<Panel>(panel()), | 187 content::Source<Panel>(panel()), |
| 218 content::NotificationService::NoDetails()); | 188 content::NotificationService::NoDetails()); |
| 219 } | 189 } |
| 220 | 190 |
| 221 bool PanelBrowserView::AcceleratorPressed( | 191 bool PanelBrowserView::AcceleratorPressed( |
| 222 const ui::Accelerator& accelerator) { | 192 const ui::Accelerator& accelerator) { |
| 223 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { | 193 if (mouse_pressed_ && accelerator.key_code() == ui::VKEY_ESCAPE) { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 } | 493 } |
| 524 | 494 |
| 525 return EndDragging(false); | 495 return EndDragging(false); |
| 526 } | 496 } |
| 527 | 497 |
| 528 // If the panel drag was cancelled before the mouse is released, do not treat | 498 // If the panel drag was cancelled before the mouse is released, do not treat |
| 529 // this as a click. | 499 // this as a click. |
| 530 if (mouse_dragging_state_ != NO_DRAGGING) | 500 if (mouse_dragging_state_ != NO_DRAGGING) |
| 531 return true; | 501 return true; |
| 532 | 502 |
| 533 // Ignore long clicks. Treated as a canceled click to be consistent with Mac. | 503 panel::ClickModifier click_modifier = panel::NO_MODIFIER; |
| 534 if (base::TimeTicks::Now() - mouse_pressed_time_ > | |
| 535 base::TimeDelta::FromMilliseconds(kShortClickThresholdMs)) | |
| 536 return true; | |
| 537 | |
| 538 #if defined(OS_WIN) && !defined(USE_AURA) | 504 #if defined(OS_WIN) && !defined(USE_AURA) |
| 539 if (base::win::IsCtrlPressed()) { | 505 if (base::win::IsCtrlPressed()) { |
|
jianli
2012/04/18 22:18:47
nit: {} is not needed.
| |
| 540 panel_->OnTitlebarClicked(panel::APPLY_TO_ALL); | 506 click_modifier = panel::APPLY_TO_ALL; |
|
jianli
2012/04/18 22:18:47
Since we're not longer supporting click-to-minimiz
| |
| 541 return true; | |
| 542 } | 507 } |
| 543 #else | 508 #else |
| 544 NOTIMPLEMENTED(); // Proceed without modifier. | 509 // Proceed without modifier. |
| 545 #endif | 510 #endif |
| 546 | 511 |
| 547 // TODO(jennb): Move remaining titlebar click handling out of here. | 512 panel_->OnTitlebarClicked(click_modifier); |
| 548 // (http://crbug.com/118431) | |
| 549 PanelStrip* panel_strip = panel_->panel_strip(); | |
| 550 if (!panel_strip) | |
| 551 return true; | |
| 552 | |
| 553 // Do not minimize the panel when we just clear the attention state. This is | |
| 554 // a hack to prevent the panel from being minimized when the user clicks on | |
| 555 // the title-bar to clear the attention. | |
| 556 if (panel_strip->type() == PanelStrip::DOCKED && | |
| 557 panel_->expansion_state() == Panel::EXPANDED && | |
| 558 base::TimeTicks::Now() - attention_cleared_time_ < | |
| 559 base::TimeDelta::FromMilliseconds(kSuspendMinimizeOnClickIntervalMs)) { | |
| 560 return true; | |
| 561 } | |
| 562 | |
| 563 if (panel_strip->type() == PanelStrip::DOCKED && | |
| 564 panel_->expansion_state() == Panel::EXPANDED) | |
| 565 panel_->SetExpansionState(Panel::MINIMIZED); | |
| 566 else | |
| 567 panel_->Activate(); | |
| 568 | |
| 569 return true; | 513 return true; |
| 570 } | 514 } |
| 571 | 515 |
| 572 bool PanelBrowserView::OnTitlebarMouseCaptureLost() { | 516 bool PanelBrowserView::OnTitlebarMouseCaptureLost() { |
| 573 if (mouse_dragging_state_ == DRAGGING_STARTED) | 517 if (mouse_dragging_state_ == DRAGGING_STARTED) |
| 574 return EndDragging(true); | 518 return EndDragging(true); |
| 575 return true; | 519 return true; |
| 576 } | 520 } |
| 577 | 521 |
| 578 bool PanelBrowserView::EndDragging(bool cancelled) { | 522 bool PanelBrowserView::EndDragging(bool cancelled) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 return expected_color == frame_view->title_label_->enabled_color(); | 686 return expected_color == frame_view->title_label_->enabled_color(); |
| 743 } | 687 } |
| 744 | 688 |
| 745 bool NativePanelTestingWin::IsWindowSizeKnown() const { | 689 bool NativePanelTestingWin::IsWindowSizeKnown() const { |
| 746 return true; | 690 return true; |
| 747 } | 691 } |
| 748 | 692 |
| 749 bool NativePanelTestingWin::IsAnimatingBounds() const { | 693 bool NativePanelTestingWin::IsAnimatingBounds() const { |
| 750 return panel_browser_view_->IsAnimatingBounds(); | 694 return panel_browser_view_->IsAnimatingBounds(); |
| 751 } | 695 } |
| OLD | NEW |