// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/ui/panels/panel.h" #include "base/logging.h" #include "chrome/browser/extensions/extension_prefs.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/panels/native_panel.h" #include "chrome/browser/ui/panels/panel_manager.h" #include "chrome/browser/ui/window_sizer.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/extensions/extension.h" #include "ui/gfx/rect.h" // static const Extension* Panel::GetExtension(Browser* browser) { // Find the extension. When we create a panel from an extension, the extension // ID is passed as the app name to the Browser. ExtensionService* extension_service = browser->GetProfile()->GetExtensionService(); return extension_service->GetExtensionById( web_app::GetExtensionIdFromApplicationName(browser->app_name()), false); } Panel::Panel(Browser* browser, const gfx::Rect& bounds) : native_panel_(NULL), expansion_state_(EXPANDED) { native_panel_ = CreateNativePanel(browser, this, bounds); } Panel::~Panel() { // Invoked by native panel so do not access native_panel_ here. } PanelManager* Panel::manager() const { return PanelManager::GetInstance(); } void Panel::SetPanelBounds(const gfx::Rect& bounds) { native_panel_->SetPanelBounds(bounds); } void Panel::SetExpansionState(ExpansionState new_expansion_state) { if (expansion_state_ == new_expansion_state) return; expansion_state_ = new_expansion_state; native_panel_->OnPanelExpansionStateChanged(expansion_state_); // The minimized panel should not get the focus. if (expansion_state_ == MINIMIZED) Deactivate(); } bool Panel::ShouldBringUpTitleBar(int mouse_x, int mouse_y) const { // Skip the expanded panel. if (expansion_state_ == Panel::EXPANDED) return false; // Let the native panel decide. return native_panel_->ShouldBringUpPanelTitleBar(mouse_x, mouse_y); } bool Panel::IsDrawingAttention() const { return native_panel_->IsDrawingAttention(); } void Panel::Show() { native_panel_->ShowPanel(); } void Panel::ShowInactive() { native_panel_->ShowPanelInactive(); } void Panel::SetBounds(const gfx::Rect& bounds) { // Ignore any SetBounds requests since the bounds are completely controlled // by panel manager. } // Close() may be called multiple times if the browser window is not ready to // close on the first attempt. void Panel::Close() { native_panel_->ClosePanel(); manager()->Remove(this); } void Panel::Activate() { native_panel_->ActivatePanel(); } void Panel::Deactivate() { native_panel_->DeactivatePanel(); } bool Panel::IsActive() const { return native_panel_->IsPanelActive(); } void Panel::FlashFrame() { native_panel_->DrawAttention(); } gfx::NativeWindow Panel::GetNativeHandle() { return native_panel_->GetNativePanelHandle(); } BrowserWindowTesting* Panel::GetBrowserWindowTesting() { NOTIMPLEMENTED(); return NULL; } StatusBubble* Panel::GetStatusBubble() { NOTIMPLEMENTED(); return NULL; } void Panel::ToolbarSizeChanged(bool is_animating){ NOTIMPLEMENTED(); } void Panel::UpdateTitleBar() { native_panel_->UpdatePanelTitleBar(); } void Panel::BookmarkBarStateChanged( BookmarkBar::AnimateChangeType change_type) { NOTIMPLEMENTED(); } void Panel::UpdateDevTools() { NOTIMPLEMENTED(); } void Panel::UpdateLoadingAnimations(bool should_animate) { NOTIMPLEMENTED(); } void Panel::SetStarredState(bool is_starred) { NOTIMPLEMENTED(); } gfx::Rect Panel::GetRestoredBounds() const { return native_panel_->GetPanelBounds(); } gfx::Rect Panel::GetBounds() const { return native_panel_->GetPanelBounds(); } bool Panel::IsMaximized() const { NOTIMPLEMENTED(); return false; } void Panel::SetFullscreen(bool fullscreen) { NOTIMPLEMENTED(); } bool Panel::IsFullscreen() const { return false; } bool Panel::IsFullscreenBubbleVisible() const { NOTIMPLEMENTED(); return false; } LocationBar* Panel::GetLocationBar() const { NOTIMPLEMENTED(); return NULL; } void Panel::SetFocusToLocationBar(bool select_all) { NOTIMPLEMENTED(); } void Panel::UpdateReloadStopState(bool is_loading, bool force) { NOTIMPLEMENTED(); } void Panel::UpdateToolbar(TabContentsWrapper* contents, bool should_restore_state) { NOTIMPLEMENTED(); } void Panel::FocusToolbar() { NOTIMPLEMENTED(); } void Panel::FocusAppMenu() { NOTIMPLEMENTED(); } void Panel::FocusBookmarksToolbar() { NOTIMPLEMENTED(); } void Panel::FocusChromeOSStatus() { NOTIMPLEMENTED(); } void Panel::RotatePaneFocus(bool forwards) { NOTIMPLEMENTED(); } bool Panel::IsBookmarkBarVisible() const { return false; } bool Panel::IsBookmarkBarAnimating() const { return false; } // This is used by extensions to decide if a window can be closed. // Always return true as panels do not have tabs that can be dragged, // during which extensions will avoid closing a window. bool Panel::IsTabStripEditable() const { return true; } bool Panel::IsToolbarVisible() const { NOTIMPLEMENTED(); return false; } void Panel::DisableInactiveFrame() { NOTIMPLEMENTED(); } void Panel::ConfirmSetDefaultSearchProvider( TabContents* tab_contents, TemplateURL* template_url, TemplateURLService* template_url_service) { NOTIMPLEMENTED(); } void Panel::ConfirmAddSearchProvider(const TemplateURL* template_url, Profile* profile) { NOTIMPLEMENTED(); } void Panel::ToggleBookmarkBar() { NOTIMPLEMENTED(); } void Panel::ShowAboutChromeDialog() { NOTIMPLEMENTED(); } void Panel::ShowUpdateChromeDialog() { NOTIMPLEMENTED(); } void Panel::ShowTaskManager() { native_panel_->ShowTaskManagerForPanel(); } void Panel::ShowBackgroundPages() { NOTIMPLEMENTED(); } void Panel::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) { NOTIMPLEMENTED(); } bool Panel::IsDownloadShelfVisible() const { return false; } DownloadShelf* Panel::GetDownloadShelf() { Browser* panel_browser = native_panel_->GetPanelBrowser(); Profile* profile = panel_browser->GetProfile(); Browser* tabbed_browser = Browser::GetTabbedBrowser(profile, true); if (!tabbed_browser) { // Set initial bounds so window will not be positioned at an offset // to this panel as panels are at the bottom of the screen. gfx::Rect window_bounds; bool maximized; WindowSizer::GetBrowserWindowBounds( std::string(), gfx::Rect(), panel_browser, &window_bounds, &maximized); Browser::CreateParams params(Browser::TYPE_TABBED, profile); params.initial_bounds = window_bounds; tabbed_browser = Browser::CreateWithParams(params); tabbed_browser->NewTab(); } tabbed_browser->window()->Show(); // Ensure download shelf is visible. return tabbed_browser->window()->GetDownloadShelf(); } void Panel::ShowRepostFormWarningDialog(TabContents* tab_contents) { NOTIMPLEMENTED(); } void Panel::ShowCollectedCookiesDialog(TabContents* tab_contents) { NOTIMPLEMENTED(); } void Panel::ShowThemeInstallBubble() { NOTIMPLEMENTED(); } void Panel::ConfirmBrowserCloseWithPendingDownloads() { NOTIMPLEMENTED(); } void Panel::ShowHTMLDialog(HtmlDialogUIDelegate* delegate, gfx::NativeWindow parent_window) { NOTIMPLEMENTED(); } void Panel::UserChangedTheme() { native_panel_->NotifyPanelOnUserChangedTheme(); } int Panel::GetExtraRenderViewHeight() const { NOTIMPLEMENTED(); return -1; } void Panel::TabContentsFocused(TabContents* tab_contents) { NOTIMPLEMENTED(); } void Panel::ShowPageInfo(Profile* profile, const GURL& url, const NavigationEntry::SSLStatus& ssl, bool show_history) { NOTIMPLEMENTED(); } void Panel::ShowAppMenu() { NOTIMPLEMENTED(); } bool Panel::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { NOTIMPLEMENTED(); return false; } void Panel::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { NOTIMPLEMENTED(); } void Panel::ShowCreateWebAppShortcutsDialog(TabContentsWrapper* tab_contents) { NOTIMPLEMENTED(); } void Panel::ShowCreateChromeAppShortcutsDialog(Profile* profile, const Extension* app) { NOTIMPLEMENTED(); } void Panel::ToggleUseCompactNavigationBar() { NOTIMPLEMENTED(); } void Panel::Cut() { NOTIMPLEMENTED(); } void Panel::Copy() { NOTIMPLEMENTED(); } void Panel::Paste() { NOTIMPLEMENTED(); } void Panel::ToggleTabStripMode() { NOTIMPLEMENTED(); } #if defined(OS_MACOSX) void Panel::OpenTabpose() { NOTIMPLEMENTED(); } void Panel::SetPresentationMode(bool presentation_mode) { NOTIMPLEMENTED(); } bool Panel::InPresentationMode() { NOTIMPLEMENTED(); return false; } #endif void Panel::PrepareForInstant() { NOTIMPLEMENTED(); } void Panel::ShowInstant(TabContentsWrapper* preview) { NOTIMPLEMENTED(); } void Panel::HideInstant(bool instant_is_active) { NOTIMPLEMENTED(); } gfx::Rect Panel::GetInstantBounds() { NOTIMPLEMENTED(); return gfx::Rect(); } WindowOpenDisposition Panel::GetDispositionForPopupBounds( const gfx::Rect& bounds) { NOTIMPLEMENTED(); return NEW_POPUP; } #if defined(OS_CHROMEOS) void Panel::ShowKeyboardOverlay(gfx::NativeWindow owning_window) { NOTIMPLEMENTED(); } #endif Browser* Panel::browser() const { return native_panel_->GetPanelBrowser(); } void Panel::DestroyBrowser() { native_panel_->DestroyPanelBrowser(); }