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" |
| 11 #include "chrome/browser/ui/panels/panel.h" | 11 #include "chrome/browser/ui/panels/panel.h" |
| 12 #include "chrome/browser/ui/panels/panel_bounds_animation.h" | 12 #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
| 13 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" | 13 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
| 14 #include "chrome/browser/ui/panels/panel_manager.h" | 14 #include "chrome/browser/ui/panels/panel_manager.h" |
| 15 #include "chrome/browser/ui/panels/panel_strip.h" | 15 #include "chrome/browser/ui/panels/panel_strip.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_frame.h" | 16 #include "chrome/browser/ui/views/frame/browser_frame.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "grit/chromium_strings.h" | 19 #include "grit/chromium_strings.h" |
| 20 #include "skia/ext/image_operations.h" | |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/gfx/canvas.h" | |
| 21 #include "ui/views/controls/button/image_button.h" | 23 #include "ui/views/controls/button/image_button.h" |
| 22 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
| 23 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 24 | 26 |
| 27 #if defined(OS_WIN) | |
| 28 #include "base/win/windows_version.h" | |
| 29 #endif | |
| 30 | |
| 25 using content::WebContents; | 31 using content::WebContents; |
| 26 | 32 |
| 27 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, | 33 NativePanel* Panel::CreateNativePanel(Browser* browser, Panel* panel, |
| 28 const gfx::Rect& bounds) { | 34 const gfx::Rect& bounds) { |
| 29 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); | 35 PanelBrowserView* view = new PanelBrowserView(browser, panel, bounds); |
| 30 (new BrowserFrame(view))->InitBrowserFrame(); | 36 (new BrowserFrame(view))->InitBrowserFrame(); |
| 31 return view; | 37 return view; |
| 32 } | 38 } |
| 33 | 39 |
| 34 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, | 40 PanelBrowserView::PanelBrowserView(Browser* browser, Panel* panel, |
| 35 const gfx::Rect& bounds) | 41 const gfx::Rect& bounds) |
| 36 : BrowserView(browser), | 42 : BrowserView(browser), |
| 37 panel_(panel), | 43 panel_(panel), |
| 38 bounds_(bounds), | 44 bounds_(bounds), |
| 39 closed_(false), | 45 closed_(false), |
| 40 focused_(false), | 46 focused_(false), |
| 41 mouse_pressed_(false), | 47 mouse_pressed_(false), |
| 42 mouse_dragging_state_(NO_DRAGGING), | 48 mouse_dragging_state_(NO_DRAGGING), |
| 43 is_drawing_attention_(false), | 49 is_drawing_attention_(false), |
| 50 force_to_paint_as_inactive_(false), | |
| 44 old_focused_view_(NULL) { | 51 old_focused_view_(NULL) { |
| 45 } | 52 } |
| 46 | 53 |
| 47 PanelBrowserView::~PanelBrowserView() { | 54 PanelBrowserView::~PanelBrowserView() { |
| 48 } | 55 } |
| 49 | 56 |
| 50 void PanelBrowserView::Init() { | 57 void PanelBrowserView::Init() { |
| 51 if (!panel_->manager()->display_settings_provider()->is_full_screen()) { | 58 if (!panel_->manager()->display_settings_provider()->is_full_screen()) { |
| 52 // TODO(prasadt): Implement this code. | 59 // TODO(prasadt): Implement this code. |
| 53 // HideThePanel. | 60 // HideThePanel. |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 } | 241 } |
| 235 | 242 |
| 236 bool PanelBrowserView::WillProcessWorkAreaChange() const { | 243 bool PanelBrowserView::WillProcessWorkAreaChange() const { |
| 237 return true; | 244 return true; |
| 238 } | 245 } |
| 239 | 246 |
| 240 void PanelBrowserView::OnWindowBeginUserBoundsChange() { | 247 void PanelBrowserView::OnWindowBeginUserBoundsChange() { |
| 241 panel_->OnPanelStartUserResizing(); | 248 panel_->OnPanelStartUserResizing(); |
| 242 } | 249 } |
| 243 | 250 |
| 251 SkBitmap PanelBrowserView::GetPreviewImage(const gfx::Size& size, bool live) { | |
|
Ben Goodger (Google)
2012/05/21 21:45:12
rather than add all this win32-specific code to wi
| |
| 252 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 253 // Returns the live captured image if requested. | |
| 254 if (live) | |
| 255 return CaptureWindowImage(); | |
| 256 | |
| 257 // No need to scale if the requested size matches. | |
| 258 int width = size.width(); | |
| 259 int height = size.height(); | |
| 260 if (capture_bitmap_->width() == width || capture_bitmap_->height() == height) | |
| 261 return *capture_bitmap_; | |
| 262 | |
| 263 SkBitmap scaled_bitmap; | |
| 264 double x_scale = static_cast<double>(width) / capture_bitmap_->width(); | |
| 265 double y_scale = static_cast<double>(height) / capture_bitmap_->height(); | |
| 266 double scale = std::min(x_scale, y_scale); | |
| 267 width = capture_bitmap_->width() * scale; | |
| 268 height = capture_bitmap_->height() * scale; | |
| 269 scaled_bitmap = skia::ImageOperations::Resize( | |
| 270 *capture_bitmap_, skia::ImageOperations::RESIZE_GOOD, width, height); | |
| 271 | |
| 272 return scaled_bitmap; | |
| 273 #else | |
| 274 return SkBitmap(); | |
| 275 #endif | |
| 276 } | |
| 277 | |
| 244 void PanelBrowserView::OnWindowEndUserBoundsChange() { | 278 void PanelBrowserView::OnWindowEndUserBoundsChange() { |
| 245 bounds_ = GetBounds(); | 279 bounds_ = GetBounds(); |
| 246 panel_->IncreaseMaxSize(bounds_.size()); | 280 panel_->IncreaseMaxSize(bounds_.size()); |
| 247 panel_->set_full_size(bounds_.size()); | 281 panel_->set_full_size(bounds_.size()); |
| 248 | 282 |
| 249 panel_->OnPanelEndUserResizing(); | 283 panel_->OnPanelEndUserResizing(); |
| 250 panel_->panel_strip()->RefreshLayout(); | 284 panel_->panel_strip()->RefreshLayout(); |
| 251 } | 285 } |
| 252 | 286 |
| 253 void PanelBrowserView::ShowPanel() { | 287 void PanelBrowserView::ShowPanel() { |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 return bounds_animator_.get() && bounds_animator_->is_animating(); | 545 return bounds_animator_.get() && bounds_animator_->is_animating(); |
| 512 } | 546 } |
| 513 | 547 |
| 514 void PanelBrowserView::EnableResizeByMouse(bool enable) { | 548 void PanelBrowserView::EnableResizeByMouse(bool enable) { |
| 515 } | 549 } |
| 516 | 550 |
| 517 void PanelBrowserView::UpdatePanelMinimizeRestoreButtonVisibility() { | 551 void PanelBrowserView::UpdatePanelMinimizeRestoreButtonVisibility() { |
| 518 GetFrameView()->UpdateTitleBarMinimizeRestoreButtonVisibility(); | 552 GetFrameView()->UpdateTitleBarMinimizeRestoreButtonVisibility(); |
| 519 } | 553 } |
| 520 | 554 |
| 521 | |
| 522 #if defined(OS_WIN) && !defined(USE_AURA) | 555 #if defined(OS_WIN) && !defined(USE_AURA) |
| 523 void PanelBrowserView::UpdateWindowAttribute(int attribute_index, | 556 void PanelBrowserView::UpdateWindowAttribute(int attribute_index, |
| 524 int attribute_value, | 557 int attribute_value, |
| 525 bool to_set) { | 558 bool to_set) { |
| 526 gfx::NativeWindow native_window = GetNativePanelHandle(); | 559 gfx::NativeWindow native_window = GetNativePanelHandle(); |
| 527 int value = ::GetWindowLong(native_window, attribute_index); | 560 int value = ::GetWindowLong(native_window, attribute_index); |
| 528 int expected_value; | 561 int expected_value; |
| 529 if (to_set) | 562 if (to_set) |
| 530 expected_value = value | attribute_value; | 563 expected_value = value | attribute_value; |
| 531 else | 564 else |
| 532 expected_value = value & ~attribute_value; | 565 expected_value = value & ~attribute_value; |
| 533 if (value != expected_value) | 566 if (value != expected_value) |
| 534 ::SetWindowLong(native_window, attribute_index, expected_value); | 567 ::SetWindowLong(native_window, attribute_index, expected_value); |
| 535 } | 568 } |
| 569 | |
| 570 SkBitmap PanelBrowserView::CaptureWindowImage() { | |
| 571 // Transfer the contents of the panel window to the screen-shot canvas' DIB. | |
| 572 HWND native_window = GetNativeHandle(); | |
| 573 gfx::Canvas canvas(bounds_.size(), false); | |
| 574 HDC target_dc = canvas.BeginPlatformPaint(); | |
| 575 HDC source_dc = ::GetDC(native_window); | |
| 576 ::BitBlt(target_dc, 0, 0, bounds_.width(), bounds_.height(), source_dc, | |
| 577 0, 0, SRCCOPY); | |
| 578 ::ReleaseDC(native_window, source_dc); | |
| 579 canvas.EndPlatformPaint(); | |
| 580 | |
| 581 return canvas.ExtractBitmap(); | |
| 582 } | |
| 536 #endif | 583 #endif |
| 537 | 584 |
| 585 void PanelBrowserView::PanelExpansionStateChanging( | |
| 586 Panel::ExpansionState old_state, Panel::ExpansionState new_state) { | |
| 587 #if defined(OS_WIN) && !defined(USE_AURA) | |
| 588 // Live preview is only available since Windows 7. | |
| 589 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
| 590 return; | |
| 591 | |
| 592 bool is_minimized = old_state != Panel::EXPANDED; | |
| 593 bool will_be_minimized = new_state != Panel::EXPANDED; | |
| 594 if (is_minimized == will_be_minimized) | |
| 595 return; | |
| 596 | |
| 597 HWND native_window = GetNativeHandle(); | |
| 598 | |
| 599 // Cache the image at this point. | |
| 600 if (will_be_minimized) { | |
| 601 // If the panel is still active (we will deactivate the minimizd panel at | |
| 602 // later time), we need to paint it immediately as inactive so that we can | |
| 603 // take a snapshot of inactive panel. | |
| 604 if (focused_) { | |
| 605 force_to_paint_as_inactive_ = true; | |
| 606 ::RedrawWindow(native_window, NULL, NULL, | |
| 607 RDW_NOCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW); | |
| 608 } | |
| 609 | |
| 610 capture_bitmap_.reset(new SkBitmap(CaptureWindowImage())); | |
| 611 } else { | |
| 612 capture_bitmap_.reset(); | |
| 613 force_to_paint_as_inactive_ = false; | |
| 614 } | |
| 615 | |
| 616 // We need to provide static bitmap to show the bitmap of the panel | |
| 617 // before it is minimized. | |
| 618 BOOL enable = will_be_minimized; | |
| 619 ::DwmSetWindowAttribute(native_window, | |
| 620 DWMWA_FORCE_ICONIC_REPRESENTATION, | |
| 621 &enable, | |
| 622 sizeof(enable)); | |
| 623 ::DwmSetWindowAttribute(native_window, | |
| 624 DWMWA_HAS_ICONIC_BITMAP, | |
| 625 &enable, | |
| 626 sizeof(enable)); | |
| 627 #endif | |
| 628 } | |
| 629 | |
| 538 // NativePanelTesting implementation. | 630 // NativePanelTesting implementation. |
| 539 class NativePanelTestingWin : public NativePanelTesting { | 631 class NativePanelTestingWin : public NativePanelTesting { |
| 540 public: | 632 public: |
| 541 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); | 633 explicit NativePanelTestingWin(PanelBrowserView* panel_browser_view); |
| 542 | 634 |
| 543 private: | 635 private: |
| 544 virtual void PressLeftMouseButtonTitlebar( | 636 virtual void PressLeftMouseButtonTitlebar( |
| 545 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; | 637 const gfx::Point& mouse_location, panel::ClickModifier modifier) OVERRIDE; |
| 546 virtual void ReleaseMouseButtonTitlebar( | 638 virtual void ReleaseMouseButtonTitlebar( |
| 547 panel::ClickModifier modifier) OVERRIDE; | 639 panel::ClickModifier modifier) OVERRIDE; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 return frame_view->close_button_->visible(); | 721 return frame_view->close_button_->visible(); |
| 630 case MINIMIZE_BUTTON: | 722 case MINIMIZE_BUTTON: |
| 631 return frame_view->minimize_button_->visible(); | 723 return frame_view->minimize_button_->visible(); |
| 632 case RESTORE_BUTTON: | 724 case RESTORE_BUTTON: |
| 633 return frame_view->restore_button_->visible(); | 725 return frame_view->restore_button_->visible(); |
| 634 default: | 726 default: |
| 635 NOTREACHED(); | 727 NOTREACHED(); |
| 636 } | 728 } |
| 637 return false; | 729 return false; |
| 638 } | 730 } |
| OLD | NEW |