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.h" | 5 #include "chrome/browser/ui/panels/panel.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 11 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| 12 #include "chrome/browser/extensions/extension_window_controller.h" | 12 #include "chrome/browser/extensions/extension_window_controller.h" |
| 13 #include "chrome/browser/lifetime/application_lifetime.h" | 13 #include "chrome/browser/lifetime/application_lifetime.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser_commands.h" | |
| 15 #include "chrome/browser/ui/panels/native_panel.h" | 16 #include "chrome/browser/ui/panels/native_panel.h" |
| 16 #include "chrome/browser/ui/panels/panel_host.h" | 17 #include "chrome/browser/ui/panels/panel_host.h" |
| 17 #include "chrome/browser/ui/panels/panel_manager.h" | 18 #include "chrome/browser/ui/panels/panel_manager.h" |
| 18 #include "chrome/browser/ui/panels/panel_strip.h" | 19 #include "chrome/browser/ui/panels/panel_strip.h" |
| 19 #include "chrome/browser/web_applications/web_app.h" | 20 #include "chrome/browser/web_applications/web_app.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
| 24 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| 27 #include "content/public/browser/user_metrics.h" | |
| 26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
| 28 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
| 29 | 31 |
| 30 using content::RenderViewHost; | 32 using content::RenderViewHost; |
| 33 using content::UserMetricsAction; | |
| 31 | 34 |
| 32 namespace panel_internal { | 35 namespace panel_internal { |
| 33 | 36 |
| 34 class PanelExtensionWindowController : public ExtensionWindowController { | 37 class PanelExtensionWindowController : public ExtensionWindowController { |
| 35 public: | 38 public: |
| 36 PanelExtensionWindowController(Panel* panel, Profile* profile); | 39 PanelExtensionWindowController(Panel* panel, Profile* profile); |
| 37 | 40 |
| 38 // Overridden from ExtensionWindowController. | 41 // Overridden from ExtensionWindowController. |
| 39 virtual int GetWindowId() const OVERRIDE; | 42 virtual int GetWindowId() const OVERRIDE; |
| 40 virtual std::string GetWindowTypeText() const OVERRIDE; | 43 virtual std::string GetWindowTypeText() const OVERRIDE; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 void Panel::InitCommandState() { | 157 void Panel::InitCommandState() { |
| 155 // All supported commands whose state isn't set automagically some other way | 158 // All supported commands whose state isn't set automagically some other way |
| 156 // (like Stop during a page load) must have their state initialized here, | 159 // (like Stop during a page load) must have their state initialized here, |
| 157 // otherwise they will be forever disabled. | 160 // otherwise they will be forever disabled. |
| 158 | 161 |
| 159 // Navigation commands | 162 // Navigation commands |
| 160 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); | 163 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true); |
| 161 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); | 164 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true); |
| 162 | 165 |
| 163 // Window management commands | 166 // Window management commands |
| 167 command_updater_.UpdateCommandEnabled(IDC_NEW_WINDOW, true); | |
|
Dmitry Titov
2012/07/11 21:27:18
It'd be nice to have a comment explaining why a pa
| |
| 168 command_updater_.UpdateCommandEnabled(IDC_NEW_INCOGNITO_WINDOW, true); | |
| 164 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); | 169 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true); |
| 165 command_updater_.UpdateCommandEnabled(IDC_EXIT, true); | 170 command_updater_.UpdateCommandEnabled(IDC_EXIT, true); |
| 166 | 171 |
| 167 // Zoom | 172 // Zoom |
| 168 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); | 173 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true); |
| 169 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); | 174 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true); |
| 170 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); | 175 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, true); |
| 171 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); | 176 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true); |
| 172 | 177 |
| 173 // Clipboard | 178 // Clipboard |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 // * cannot grow or shrink to go beyond [min_height, max_height] | 315 // * cannot grow or shrink to go beyond [min_height, max_height] |
| 311 int new_height = size.height(); | 316 int new_height = size.height(); |
| 312 if (new_height > max_size_.height()) | 317 if (new_height > max_size_.height()) |
| 313 new_height = max_size_.height(); | 318 new_height = max_size_.height(); |
| 314 if (new_height < min_size_.height()) | 319 if (new_height < min_size_.height()) |
| 315 new_height = min_size_.height(); | 320 new_height = min_size_.height(); |
| 316 | 321 |
| 317 return gfx::Size(new_width, new_height); | 322 return gfx::Size(new_width, new_height); |
| 318 } | 323 } |
| 319 | 324 |
| 325 void Panel::ContentsZoomChange(bool zoom_in) { | |
| 326 command_updater()->ExecuteCommand(zoom_in ? IDC_ZOOM_PLUS : IDC_ZOOM_MINUS); | |
| 327 } | |
| 328 | |
| 329 void Panel::HandleKeyboardEvent(const content::NativeWebKeyboardEvent& event) { | |
| 330 native_panel_->HandlePanelKeyboardEvent(event); | |
| 331 } | |
| 332 | |
| 320 void Panel::SetAlwaysOnTop(bool on_top) { | 333 void Panel::SetAlwaysOnTop(bool on_top) { |
| 321 if (always_on_top_ == on_top) | 334 if (always_on_top_ == on_top) |
| 322 return; | 335 return; |
| 323 always_on_top_ = on_top; | 336 always_on_top_ = on_top; |
| 324 native_panel_->SetPanelAlwaysOnTop(on_top); | 337 native_panel_->SetPanelAlwaysOnTop(on_top); |
| 325 } | 338 } |
| 326 | 339 |
| 327 void Panel::EnableResizeByMouse(bool enable) { | 340 void Panel::EnableResizeByMouse(bool enable) { |
| 328 DCHECK(native_panel_); | 341 DCHECK(native_panel_); |
| 329 native_panel_->EnableResizeByMouse(enable); | 342 native_panel_->EnableResizeByMouse(enable); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 } | 526 } |
| 514 | 527 |
| 515 void Panel::ExecuteCommandWithDisposition(int id, | 528 void Panel::ExecuteCommandWithDisposition(int id, |
| 516 WindowOpenDisposition disposition) { | 529 WindowOpenDisposition disposition) { |
| 517 if (!GetWebContents()) | 530 if (!GetWebContents()) |
| 518 return; | 531 return; |
| 519 | 532 |
| 520 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command " | 533 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command " |
| 521 << id; | 534 << id; |
| 522 switch (id) { | 535 switch (id) { |
| 523 case IDC_RELOAD: // etc | 536 // Navigation |
| 524 // TODO(jennb): implement. | 537 case IDC_RELOAD: |
| 538 content::RecordAction(UserMetricsAction("Reload")); | |
| 539 GetWebContents()->GetController().Reload(true); | |
| 540 break; | |
| 541 case IDC_RELOAD_IGNORING_CACHE: | |
| 542 content::RecordAction(UserMetricsAction("ReloadIgnoringCache")); | |
| 543 GetWebContents()->GetController().ReloadIgnoringCache(true); | |
| 544 break; | |
| 545 case IDC_STOP: | |
| 546 content::RecordAction(UserMetricsAction("Stop")); | |
| 547 GetWebContents()->Stop(); | |
| 548 break; | |
| 549 | |
| 550 // Window management | |
| 551 case IDC_NEW_WINDOW: | |
| 552 chrome::NewEmptyWindow(profile()); | |
| 553 break; | |
| 554 case IDC_NEW_INCOGNITO_WINDOW: | |
| 555 chrome::NewEmptyWindow(profile()->GetOffTheRecordProfile()); | |
| 556 break; | |
| 557 | |
| 558 // Clipboard | |
| 559 case IDC_COPY: | |
| 560 content::RecordAction(UserMetricsAction("Copy")); | |
| 561 native_panel_->PanelCopy(); | |
| 562 break; | |
| 563 case IDC_CUT: | |
| 564 content::RecordAction(UserMetricsAction("Cut")); | |
| 565 native_panel_->PanelCut(); | |
| 566 break; | |
| 567 case IDC_PASTE: | |
| 568 content::RecordAction(UserMetricsAction("Paste")); | |
| 569 native_panel_->PanelPaste(); | |
| 570 break; | |
| 571 | |
| 572 // Zoom | |
| 573 case IDC_ZOOM_PLUS: | |
| 574 chrome::Zoom(GetWebContents(), profile(), content::PAGE_ZOOM_IN); | |
| 575 break; | |
| 576 case IDC_ZOOM_NORMAL: | |
| 577 chrome::Zoom(GetWebContents(), profile(), content::PAGE_ZOOM_RESET); | |
| 578 break; | |
| 579 case IDC_ZOOM_MINUS: | |
| 580 chrome::Zoom(GetWebContents(), profile(), content::PAGE_ZOOM_OUT); | |
| 581 break; | |
| 582 | |
| 525 default: | 583 default: |
| 526 LOG(WARNING) << "Received unimplemented command: " << id; | 584 LOG(WARNING) << "Received unimplemented command: " << id; |
| 527 break; | 585 break; |
| 528 } | 586 } |
| 529 } | 587 } |
| 530 | 588 |
| 531 bool Panel::ExecuteCommandIfEnabled(int id) { | 589 bool Panel::ExecuteCommandIfEnabled(int id) { |
| 532 if (command_updater()->SupportsCommand(id) && | 590 if (command_updater()->SupportsCommand(id) && |
| 533 command_updater()->IsCommandEnabled(id)) { | 591 command_updater()->IsCommandEnabled(id)) { |
| 534 ExecuteCommandWithDisposition(id, CURRENT_TAB); | 592 ExecuteCommandWithDisposition(id, CURRENT_TAB); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 | 732 |
| 675 SkBitmap Panel::GetCurrentPageIcon() const { | 733 SkBitmap Panel::GetCurrentPageIcon() const { |
| 676 return panel_host_->GetPageIcon(); | 734 return panel_host_->GetPageIcon(); |
| 677 } | 735 } |
| 678 | 736 |
| 679 void Panel::UpdateTitleBar() { | 737 void Panel::UpdateTitleBar() { |
| 680 native_panel_->UpdatePanelTitleBar(); | 738 native_panel_->UpdatePanelTitleBar(); |
| 681 } | 739 } |
| 682 | 740 |
| 683 void Panel::LoadingStateChanged(bool is_loading) { | 741 void Panel::LoadingStateChanged(bool is_loading) { |
| 742 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | |
| 684 native_panel_->UpdatePanelLoadingAnimations(is_loading); | 743 native_panel_->UpdatePanelLoadingAnimations(is_loading); |
| 685 UpdateTitleBar(); | 744 UpdateTitleBar(); |
| 686 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); | |
| 687 } | 745 } |
| OLD | NEW |