Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/ui/panels/panel.cc

Issue 11669018: Support dragging panels to stack and snap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Change per feedback Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/devtools/devtools_window.h" 11 #include "chrome/browser/devtools/devtools_window.h"
12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 12 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
13 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h" 13 #include "chrome/browser/extensions/api/tabs/tabs_windows_api.h"
14 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" 14 #include "chrome/browser/extensions/api/tabs/windows_event_router.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_system.h" 16 #include "chrome/browser/extensions/extension_system.h"
17 #include "chrome/browser/extensions/extension_tab_util.h" 17 #include "chrome/browser/extensions/extension_tab_util.h"
18 #include "chrome/browser/extensions/window_controller.h" 18 #include "chrome/browser/extensions/window_controller.h"
19 #include "chrome/browser/extensions/window_controller_list.h" 19 #include "chrome/browser/extensions/window_controller_list.h"
20 #include "chrome/browser/lifetime/application_lifetime.h" 20 #include "chrome/browser/lifetime/application_lifetime.h"
21 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/themes/theme_service.h" 22 #include "chrome/browser/themes/theme_service.h"
23 #include "chrome/browser/themes/theme_service_factory.h" 23 #include "chrome/browser/themes/theme_service_factory.h"
24 #include "chrome/browser/ui/panels/native_panel.h" 24 #include "chrome/browser/ui/panels/native_panel.h"
25 #include "chrome/browser/ui/panels/panel_collection.h" 25 #include "chrome/browser/ui/panels/panel_collection.h"
26 #include "chrome/browser/ui/panels/panel_host.h" 26 #include "chrome/browser/ui/panels/panel_host.h"
27 #include "chrome/browser/ui/panels/panel_manager.h" 27 #include "chrome/browser/ui/panels/panel_manager.h"
28 #include "chrome/browser/ui/panels/stacked_panel_collection.h"
28 #include "chrome/browser/web_applications/web_app.h" 29 #include "chrome/browser/web_applications/web_app.h"
29 #include "chrome/common/chrome_notification_types.h" 30 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/extensions/extension.h" 31 #include "chrome/common/extensions/extension.h"
31 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/notification_source.h" 33 #include "content/public/browser/notification_source.h"
33 #include "content/public/browser/notification_types.h" 34 #include "content/public/browser/notification_types.h"
34 #include "content/public/browser/render_view_host.h" 35 #include "content/public/browser/render_view_host.h"
35 #include "content/public/browser/user_metrics.h" 36 #include "content/public/browser/user_metrics.h"
36 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
37 #include "ui/gfx/image/image.h" 38 #include "ui/gfx/image/image.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 239 }
239 240
240 Profile* Panel::profile() const { 241 Profile* Panel::profile() const {
241 return profile_; 242 return profile_;
242 } 243 }
243 244
244 const std::string Panel::extension_id() const { 245 const std::string Panel::extension_id() const {
245 return web_app::GetExtensionIdFromApplicationName(app_name_); 246 return web_app::GetExtensionIdFromApplicationName(app_name_);
246 } 247 }
247 248
249 StackedPanelCollection* Panel::stack() const {
250 return collection_->type() == PanelCollection::STACKED ?
251 static_cast<StackedPanelCollection*>(collection_) : NULL;
252 }
253
248 content::WebContents* Panel::GetWebContents() const { 254 content::WebContents* Panel::GetWebContents() const {
249 return panel_host_.get() ? panel_host_->web_contents() : NULL; 255 return panel_host_.get() ? panel_host_->web_contents() : NULL;
250 } 256 }
251 257
252 bool Panel::CanMinimize() const { 258 bool Panel::CanMinimize() const {
253 return collection_ && collection_->CanMinimizePanel(this) && !IsMinimized(); 259 return collection_ && collection_->CanMinimizePanel(this) && !IsMinimized();
254 } 260 }
255 261
256 bool Panel::CanRestore() const { 262 bool Panel::CanRestore() const {
257 return collection_ && collection_->CanMinimizePanel(this) && IsMinimized(); 263 return collection_ && collection_->CanMinimizePanel(this) && IsMinimized();
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
759 } 765 }
760 766
761 void Panel::OnWindowClosing() { 767 void Panel::OnWindowClosing() {
762 if (GetWebContents()) { 768 if (GetWebContents()) {
763 native_panel_->DetachWebContents(GetWebContents()); 769 native_panel_->DetachWebContents(GetWebContents());
764 panel_host_->DestroyWebContents(); 770 panel_host_->DestroyWebContents();
765 } 771 }
766 } 772 }
767 773
768 string16 Panel::GetWindowTitle() const { 774 string16 Panel::GetWindowTitle() const {
775 // |contents| can be NULL during the window's creation.
769 content::WebContents* contents = GetWebContents(); 776 content::WebContents* contents = GetWebContents();
770 string16 title;
771
772 // |contents| can be NULL during the window's creation.
773 if (contents) { 777 if (contents) {
774 title = contents->GetTitle(); 778 string16 title = contents->GetTitle();
775 FormatTitleForDisplay(&title); 779 FormatTitleForDisplay(&title);
780 if (!title.empty())
781 return title;
776 } 782 }
777 783
778 if (title.empty()) 784 // Then try the extension manifest name. At last, app name is used.
Dmitry Titov 2013/01/09 02:29:50 This is unrelated change. Can it be moved to a sep
jianli 2013/01/09 21:00:59 Done.
779 title = UTF8ToUTF16(app_name()); 785 const extensions::Extension* extension = GetExtension();
780 786 return UTF8ToUTF16(extension && !extension->name().empty() ?
781 return title; 787 extension->name() : app_name());
782 } 788 }
783 789
784 // static 790 // static
785 void Panel::FormatTitleForDisplay(string16* title) { 791 void Panel::FormatTitleForDisplay(string16* title) {
786 size_t current_index = 0; 792 size_t current_index = 0;
787 size_t match_index; 793 size_t match_index;
788 while ((match_index = title->find(L'\n', current_index)) != string16::npos) { 794 while ((match_index = title->find(L'\n', current_index)) != string16::npos) {
789 title->replace(match_index, 1, string16()); 795 title->replace(match_index, 1, string16());
790 current_index = match_index; 796 current_index = match_index;
791 } 797 }
(...skipping 10 matching lines...) Expand all
802 void Panel::LoadingStateChanged(bool is_loading) { 808 void Panel::LoadingStateChanged(bool is_loading) {
803 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading); 809 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
804 native_panel_->UpdatePanelLoadingAnimations(is_loading); 810 native_panel_->UpdatePanelLoadingAnimations(is_loading);
805 UpdateTitleBar(); 811 UpdateTitleBar();
806 } 812 }
807 813
808 void Panel::WebContentsFocused(content::WebContents* contents) { 814 void Panel::WebContentsFocused(content::WebContents* contents) {
809 native_panel_->PanelWebContentsFocused(contents); 815 native_panel_->PanelWebContentsFocused(contents);
810 } 816 }
811 817
818 void Panel::UpdateStackingProperty() {
819 native_panel_->UpdatePanelStackingProperty();
820 }
821
822 void Panel::MoveBy(const gfx::Vector2d& delta_origin) {
Dmitry Titov 2013/01/09 02:29:50 Naming: MoveByInstantly would better reflect what
jianli 2013/01/09 21:00:59 Done.
823 gfx::Rect bounds = GetBounds();
824 bounds.Offset(delta_origin);
825 SetPanelBoundsInstantly(bounds);
826 }
827
812 const extensions::Extension* Panel::GetExtension() const { 828 const extensions::Extension* Panel::GetExtension() const {
813 ExtensionService* extension_service = 829 ExtensionService* extension_service =
814 extensions::ExtensionSystem::Get(profile())->extension_service(); 830 extensions::ExtensionSystem::Get(profile())->extension_service();
815 if (!extension_service || !extension_service->is_ready()) 831 if (!extension_service || !extension_service->is_ready())
816 return NULL; 832 return NULL;
817 return extension_service->GetExtensionById(extension_id(), false); 833 return extension_service->GetExtensionById(extension_id(), false);
818 } 834 }
819 835
820 void Panel::UpdateAppIcon() { 836 void Panel::UpdateAppIcon() {
821 const extensions::Extension* extension = GetExtension(); 837 const extensions::Extension* extension = GetExtension();
(...skipping 17 matching lines...) Expand all
839 app_icon_ = image; 855 app_icon_ = image;
840 native_panel_->UpdatePanelTitleBar(); 856 native_panel_->UpdatePanelTitleBar();
841 } 857 }
842 app_icon_loader_.reset(); 858 app_icon_loader_.reset();
843 859
844 content::NotificationService::current()->Notify( 860 content::NotificationService::current()->Notify(
845 chrome::NOTIFICATION_PANEL_APP_ICON_LOADED, 861 chrome::NOTIFICATION_PANEL_APP_ICON_LOADED,
846 content::Source<Panel>(this), 862 content::Source<Panel>(this),
847 content::NotificationService::NoDetails()); 863 content::NotificationService::NoDetails());
848 } 864 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698