diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 21:49:29 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-03 21:49:29 +0000 |
commit | 1c9e90e17741f9c34f4cbe7f3e68a8300ed24e08 (patch) | |
tree | a71ad0a43ff69da776078899976dce66f4bf302c /chrome/browser/tab_contents | |
parent | 9cea0d120a21c80f812be19cc7eb6e3fffdd6913 (diff) | |
download | chromium_src-1c9e90e17741f9c34f4cbe7f3e68a8300ed24e08.zip chromium_src-1c9e90e17741f9c34f4cbe7f3e68a8300ed24e08.tar.gz chromium_src-1c9e90e17741f9c34f4cbe7f3e68a8300ed24e08.tar.bz2 |
Remove NativeUI, HistoryTabUI, DownloadsTabUI since they've been superceded.
Review URL: http://codereview.chromium.org/39005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10832 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/native_ui_contents.cc | 670 | ||||
-rw-r--r-- | chrome/browser/tab_contents/native_ui_contents.h | 295 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_factory.cc | 7 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_type.h | 1 |
4 files changed, 0 insertions, 973 deletions
diff --git a/chrome/browser/tab_contents/native_ui_contents.cc b/chrome/browser/tab_contents/native_ui_contents.cc deleted file mode 100644 index 11b7ba5..0000000 --- a/chrome/browser/tab_contents/native_ui_contents.cc +++ /dev/null @@ -1,670 +0,0 @@ -// Copyright (c) 2006-2008 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/tab_contents/native_ui_contents.h" - -#include "chrome/browser/browser.h" -#include "chrome/browser/history_tab_ui.h" -#include "chrome/browser/tab_contents/navigation_entry.h" -#include "chrome/browser/views/download_tab_view.h" -#include "chrome/common/drag_drop_types.h" -#include "chrome/common/gfx/chrome_canvas.h" -#include "chrome/common/gfx/chrome_font.h" -#include "chrome/common/l10n_util.h" -#include "chrome/common/os_exchange_data.h" -#include "chrome/common/resource_bundle.h" -#include "chrome/views/background.h" -#include "chrome/views/checkbox.h" -#include "chrome/views/grid_layout.h" -#include "chrome/views/image_view.h" -#include "chrome/views/root_view.h" -#include "chrome/views/scroll_view.h" -#include "chrome/views/throbber.h" -#include "chrome/views/widget_win.h" -#include "grit/generated_resources.h" - -using views::ColumnSet; -using views::GridLayout; - -//static -bool NativeUIContents::g_ui_factories_initialized = false; - -// The URL scheme currently used. -static const char kNativeUIContentsScheme[] = "chrome-nativeui"; - -// Unique page id generator. -static int g_next_page_id = 0; - -// The x-position of the title. -static const int kDestinationTitleOffset = 38; - -// The x-position of the search field. -static const int kDestinationSearchOffset = 128; - -// The width of the search field. -static const int kDestinationSearchWidth = 360; - -// Padding between columns -static const int kDestinationSmallerMargin = 8; - -// The background color. -static const SkColor kBackground = SkColorSetRGB(255, 255, 255); - -// The color of the bottom margin. -static const SkColor kBottomMarginColor = SkColorSetRGB(246, 249, 255); - -// The height of the bottom margin. -static const int kBottomMargin = 5; - -// The Chrome product logo. -static const SkBitmap* kProductLogo = NULL; - -// Padding around the product logo. -static const int kProductLogoPadding = 8; - -namespace { - -// NativeRootView -------------------------------------------------------------- - -// NativeRootView is a trivial RootView subclass that allows URL drops and -// forwards them to the NavigationController to open. - -class NativeRootView : public views::RootView { - public: - explicit NativeRootView(NativeUIContents* host) - : RootView(host), - host_(host) { } - - virtual ~NativeRootView() { } - - virtual bool CanDrop(const OSExchangeData& data) { - return data.HasURL(); - } - - virtual int OnDragUpdated(const views::DropTargetEvent& event) { - if (event.GetSourceOperations() & DragDropTypes::DRAG_COPY) - return DragDropTypes::DRAG_COPY; - if (event.GetSourceOperations() & DragDropTypes::DRAG_LINK) - return DragDropTypes::DRAG_LINK; - return DragDropTypes::DRAG_NONE; - } - - virtual int OnPerformDrop(const views::DropTargetEvent& event) { - GURL url; - std::wstring title; - if (!event.GetData().GetURLAndTitle(&url, &title) || !url.is_valid()) - return DragDropTypes::DRAG_NONE; - host_->controller()->LoadURL(url, GURL(), PageTransition::GENERATED); - return OnDragUpdated(event); - } - - private: - NativeUIContents* host_; - - DISALLOW_EVIL_CONSTRUCTORS(NativeRootView); -}; - -} // namespace - - -// Returns the end of the scheme and end of the host. This is temporary until -// bug 772411 is fixed. -static void GetSchemeAndHostEnd(const GURL& url, - size_t* scheme_end, - size_t* host_end) { - const std::string spec = url.spec(); - *scheme_end = spec.find("//"); - DCHECK(*scheme_end != std::string::npos); - - *host_end = spec.find('/', *scheme_end + 2); - if (*host_end == std::string::npos) - *host_end = spec.size(); -} - -NativeUIContents::NativeUIContents(Profile* profile) - : TabContents(TAB_CONTENTS_NATIVE_UI), - is_visible_(false), - current_ui_(NULL), - current_view_(NULL), - state_(new PageState()) { - if (!g_ui_factories_initialized) { - InitializeNativeUIFactories(); - g_ui_factories_initialized = true; - } -} - -NativeUIContents::~NativeUIContents() { - if (current_ui_) { - views::RootView* root_view = GetRootView(); - current_ui_->WillBecomeInvisible(this); - root_view->RemoveChildView(current_view_); - current_ui_ = NULL; - current_view_ = NULL; - } - - STLDeleteContainerPairSecondPointers(path_to_native_uis_.begin(), - path_to_native_uis_.end()); -} - -void NativeUIContents::CreateView() { - set_delete_on_destroy(false); - WidgetWin::Init(GetDesktopWindow(), gfx::Rect(), false); -} - -LRESULT NativeUIContents::OnCreate(LPCREATESTRUCT create_struct) { - // Set the view container initial size. - CRect tmp; - ::GetWindowRect(GetHWND(), &tmp); - tmp.right = tmp.Width(); - tmp.bottom = tmp.Height(); - tmp.left = tmp.top = 0; - - // Install the focus manager so we get notified of Tab key events. - views::FocusManager::InstallFocusSubclass(GetHWND(), NULL); - GetRootView()->set_background(new NativeUIBackground); - return 0; -} - -void NativeUIContents::OnDestroy() { - views::FocusManager::UninstallFocusSubclass(GetHWND()); -} - -void NativeUIContents::OnSize(UINT size_command, const CSize& new_size) { - Layout(); - ::RedrawWindow(GetHWND(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN); -} - -void NativeUIContents::OnWindowPosChanged(WINDOWPOS* position) { - // NOTE: this may be invoked even when the visbility didn't change, in which - // case hiding and showing are both false. - const bool hiding = (position->flags & SWP_HIDEWINDOW) == SWP_HIDEWINDOW; - const bool showing = (position->flags & SWP_SHOWWINDOW) == SWP_SHOWWINDOW; - if (hiding || showing) { - if (is_visible_ != showing) { - is_visible_ = showing; - if (current_ui_) { - if (is_visible_) - current_ui_->WillBecomeVisible(this); - else - current_ui_->WillBecomeInvisible(this); - } - } - } - ChangeSize(0, CSize(position->cx, position->cy)); - - SetMsgHandled(FALSE); -} - -void NativeUIContents::GetContainerBounds(gfx::Rect* out) const { - GetBounds(out, false); -} - -void NativeUIContents::SetPageState(PageState* page_state) { - if (!page_state) - page_state = new PageState(); - state_.reset(page_state); - NavigationController* ctrl = controller(); - if (ctrl) { - int ne_index = ctrl->GetLastCommittedEntryIndex(); - NavigationEntry* ne = ctrl->GetEntryAtIndex(ne_index); - if (ne) { - // NavigationEntry is null if we're being restored. - DCHECK(ne); - std::string rep; - state_->GetByteRepresentation(&rep); - ne->set_content_state(rep); - ctrl->NotifyEntryChanged(ne, ne_index); - } - } -} - -bool NativeUIContents::NavigateToPendingEntry(bool reload) { - views::RootView* root_view = GetRootView(); - DCHECK(root_view); - - if (current_ui_) { - current_ui_->WillBecomeInvisible(this); - root_view->RemoveChildView(current_view_); - current_ui_ = NULL; - current_view_ = NULL; - } - - NavigationEntry* pending_entry = controller()->GetPendingEntry(); - NativeUI* new_ui = GetNativeUIForURL(pending_entry->url()); - if (new_ui) { - current_ui_ = new_ui; - is_visible_ = true; - current_ui_->WillBecomeVisible(this); - current_view_ = new_ui->GetView(); - root_view->AddChildView(current_view_); - - std::string s = pending_entry->content_state(); - if (s.empty()) - state_->InitWithURL(pending_entry->url()); - else - state_->InitWithBytes(s); - - current_ui_->Navigate(*state_); - Layout(); - } - - // Commit the new load in the navigation controller. If the ID of the - // NavigationEntry we were given was -1, that means this is a new load, so - // we have to generate a new ID. - controller()->CommitPendingEntry(); - - // Populate the committed entry. - NavigationEntry* committed_entry = controller()->GetLastCommittedEntry(); - committed_entry->set_title(GetDefaultTitle()); - committed_entry->favicon().set_bitmap(GetFavIcon()); - committed_entry->favicon().set_is_valid(true); - if (new_ui) { - // Strip out the query params, they should have moved to state. - // TODO(sky): use GURL methods for replacements once bug is fixed. - size_t scheme_end, host_end; - GetSchemeAndHostEnd(committed_entry->url(), &scheme_end, &host_end); - committed_entry->set_url( - GURL(committed_entry->url().spec().substr(0, host_end))); - } - std::string content_state; - state_->GetByteRepresentation(&content_state); - committed_entry->set_content_state(content_state); - - // Broadcast the fact that we just updated all that crap. - controller()->NotifyEntryChanged( - committed_entry, - controller()->GetIndexOfEntry(committed_entry)); - return true; -} - -void NativeUIContents::Layout() { - if (current_view_) { - views::RootView* root_view = GetRootView(); - current_view_->SetBounds(0, 0, root_view->width(), - root_view->height()); - current_view_->Layout(); - } -} - -const std::wstring NativeUIContents::GetDefaultTitle() const { - if (current_ui_) - return current_ui_->GetTitle(); - else - return std::wstring(); -} - -SkBitmap NativeUIContents::GetFavIcon() const { - int icon_id; - - if (current_ui_) - icon_id = current_ui_->GetFavIconID(); - else - icon_id = IDR_DEFAULT_FAVICON; - - return *ResourceBundle::GetSharedInstance().GetBitmapNamed(icon_id); -} - -void NativeUIContents::DidBecomeSelected() { - TabContents::DidBecomeSelected(); - Layout(); -} - -void NativeUIContents::SetInitialFocus() { - if (!current_ui_ || !current_ui_->SetInitialFocus()) { - int tab_index; - Browser* browser = Browser::GetBrowserForController( - this->controller(), &tab_index); - if (browser) - browser->SetFocusToLocationBar(); - else - TabContents::SetInitialFocus(); // Will set focus to our HWND. - } -} - -void NativeUIContents::SetIsLoading(bool is_loading, - LoadNotificationDetails* details) { - TabContents::SetIsLoading(is_loading, details); -} - -// FocusTraversable Implementation -views::View* NativeUIContents::FindNextFocusableView( - views::View* starting_view, bool reverse, - views::FocusTraversable::Direction direction, bool dont_loop, - views::FocusTraversable** focus_traversable, - views::View** focus_traversable_view) { - return GetRootView()->FindNextFocusableView( - starting_view, reverse, direction, dont_loop, - focus_traversable, focus_traversable_view); -} - -//static -std::string NativeUIContents::GetScheme() { - return kNativeUIContentsScheme; -} - -//static -void NativeUIContents::InitializeNativeUIFactories() { - RegisterNativeUIFactory(DownloadTabUI::GetURL(), - DownloadTabUI::GetNativeUIFactory()); - RegisterNativeUIFactory(HistoryTabUI::GetURL(), - HistoryTabUI::GetNativeUIFactory()); -} - -// static -std::string NativeUIContents::GetFactoryKey(const GURL& url) { - size_t scheme_end; - size_t host_end; - GetSchemeAndHostEnd(url, &scheme_end, &host_end); - return url.spec().substr(scheme_end + 2, host_end - scheme_end - 2); -} - -typedef std::map<std::string, NativeUIFactory*> PathToFactoryMap; - -static PathToFactoryMap* g_path_to_factory = NULL; - -//static -void NativeUIContents::RegisterNativeUIFactory(const GURL& url, - NativeUIFactory* factory) { - const std::string key = GetFactoryKey(url); - - if (!g_path_to_factory) - g_path_to_factory = new PathToFactoryMap; - - PathToFactoryMap::iterator i = g_path_to_factory->find(key); - if (i != g_path_to_factory->end()) { - delete i->second; - g_path_to_factory->erase(i); - } - (*g_path_to_factory)[key] = factory; -} - -views::RootView* NativeUIContents::CreateRootView() { - return new NativeRootView(this); -} - -//static -NativeUI* NativeUIContents::InstantiateNativeUIForURL( - const GURL& url, NativeUIContents* contents) { - if (!g_path_to_factory) - return NULL; - - const std::string key = GetFactoryKey(url); - - NativeUIFactory* factory = (*g_path_to_factory)[key]; - if (factory) - return factory->CreateNativeUIForURL(url, contents); - else - return NULL; -} - -NativeUI* NativeUIContents::GetNativeUIForURL(const GURL& url) { - const std::string key = GetFactoryKey(url); - - PathToUI::iterator i = path_to_native_uis_.find(key); - if (i != path_to_native_uis_.end()) - return i->second; - - NativeUI* ui = InstantiateNativeUIForURL(url, this); - if (ui) - path_to_native_uis_[key] = ui; - return ui; -} - - -//////////////////////////////////////////////////////////////////////////////// -// -// Standard NativeUI background implementation. -// -//////////////////////////////////////////////////////////////////////////////// -NativeUIBackground::NativeUIBackground() { -} - -NativeUIBackground::~NativeUIBackground() { -} - -void NativeUIBackground::Paint(ChromeCanvas* canvas, - views::View* view) const { - static const SkColor kBackground = SkColorSetRGB(255, 255, 255); - canvas->FillRectInt(kBackground, 0, 0, view->width(), view->height()); -} - -///////////////////////////////////////////////////////////////////////////// -// -// SearchableUIBackground -// A Background subclass to be used with SearchableUIContainer objects. -// Paint() is overridden to do nothing here; the background of the bar is -// painted in SearchableUIContainer::Paint. This class is necessary -// only for native controls to be able to get query the background -// brush. - -class SearchableUIBackground : public views::Background { - public: - explicit SearchableUIBackground(SkColor native_control_color) { - SetNativeControlColor(native_control_color); - } - virtual ~SearchableUIBackground() {}; - - // Empty implementation. - // The actual painting of the bar happens in SearchableUIContainer::Paint. - virtual void Paint(ChromeCanvas* canvas, views::View* view) const { } - - private: - DISALLOW_EVIL_CONSTRUCTORS(SearchableUIBackground); -}; - -///////////////////////////////////////////////////////////////////////////// -// -// SearchableUIContainer implementation. -// -///////////////////////////////////////////////////////////////////////////// - -SearchableUIContainer::SearchableUIContainer( - SearchableUIContainer::Delegate* delegate) - : delegate_(delegate), - search_field_(NULL), - title_link_(NULL), - title_image_(NULL), - scroll_view_(NULL) { - title_link_ = new views::Link; - ResourceBundle& resource_bundle = ResourceBundle::GetSharedInstance(); - ChromeFont title_font(resource_bundle - .GetFont(ResourceBundle::WebFont).DeriveFont(2)); - title_link_->SetFont(title_font); - title_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); - title_link_->SetController(this); - - title_image_ = new views::ImageView(); - title_image_->SetVisible(false); - - // Get the product logo - if (!kProductLogo) { - kProductLogo = resource_bundle.GetBitmapNamed(IDR_PRODUCT_LOGO); - } - - product_logo_ = new views::ImageView(); - product_logo_->SetVisible(true); - product_logo_->SetImage(*kProductLogo); - AddChildView(product_logo_); - - search_field_ = new views::TextField; - search_field_->SetFont(ResourceBundle::GetSharedInstance().GetFont( - ResourceBundle::WebFont)); - search_field_->SetController(this); - - scroll_view_ = new views::ScrollView; - scroll_view_->set_background( - views::Background::CreateSolidBackground(kBackground)); - - // Set background class so that native controls can get a color. - set_background(new SearchableUIBackground(kBackground)); - - throbber_ = new views::SmoothedThrobber(50); - - GridLayout* layout = new GridLayout(this); - // View owns the LayoutManager and will delete it along with all the columns - // we create here. - SetLayoutManager(layout); - - search_button_ = - new views::NativeButton(std::wstring()); - search_button_->SetFont(resource_bundle.GetFont(ResourceBundle::WebFont)); - search_button_->SetListener(this); - - // Set a background color for the search button. If SearchableUIContainer - // provided a background, then the search button could inherit that instead. - search_button_->set_background(new SearchableUIBackground(kBackground)); - - // For the first row (icon, title/text field, search button and throbber). - ColumnSet* column_set = layout->AddColumnSet(0); - column_set->AddPaddingColumn(0, kDestinationTitleOffset); - - // Add the icon column. - column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, - GridLayout::USE_PREF, - kDestinationSearchOffset - kDestinationTitleOffset - - kDestinationSmallerMargin, - kDestinationSearchOffset - kDestinationTitleOffset - - kDestinationSmallerMargin); - column_set->AddPaddingColumn(0, kDestinationSmallerMargin); - - // Add the title/search field column. - column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, - GridLayout::USE_PREF, kDestinationSearchWidth, - kDestinationSearchWidth); - column_set->AddPaddingColumn(0, kDestinationSmallerMargin); - - // Add the search button column. - column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - column_set->AddPaddingColumn(0, kDestinationSmallerMargin); - - // Add the throbber column. - column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, - GridLayout::USE_PREF, 0, 0); - - // For the scroll view. - column_set = layout->AddColumnSet(1); - column_set->AddPaddingColumn(0, 1); - column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, - GridLayout::USE_PREF, 0, 0); - - layout->AddPaddingRow(0, kDestinationSmallerMargin); - layout->StartRow(0, 0); - layout->AddView(title_image_, 1, 2); - layout->AddView(title_link_); - - layout->StartRow(0, 0); - layout->SkipColumns(1); - layout->AddView(search_field_); - layout->AddView(search_button_); - layout->AddView(throbber_); - - layout->AddPaddingRow(0, kDestinationSmallerMargin); - layout->StartRow(1, 1); - layout->AddView(scroll_view_); -} - -SearchableUIContainer::~SearchableUIContainer() { -} - -void SearchableUIContainer::SetContents(views::View* contents) { - // The column view will resize to accomodate long titles. - title_link_->SetText(delegate_->GetTitle()); - - int section_icon_id = delegate_->GetSectionIconID(); - if (section_icon_id != 0) { - title_image_->SetImage(*ResourceBundle::GetSharedInstance(). - GetBitmapNamed(section_icon_id)); - title_image_->SetVisible(true); - } - - search_button_->SetLabel(delegate_->GetSearchButtonText()); - scroll_view_->SetContents(contents); -} - -views::View* SearchableUIContainer::GetContents() { - return scroll_view_->GetContents(); -} - -void SearchableUIContainer::Layout() { - View::Layout(); - - gfx::Size search_button_size = search_button_->GetPreferredSize(); - gfx::Size product_logo_size = product_logo_->GetPreferredSize(); - - int field_width = kDestinationSearchOffset + - kDestinationSearchWidth + - kDestinationSmallerMargin + - static_cast<int>(search_button_size.width()) + - kDestinationSmallerMargin; - - product_logo_->SetBounds(std::max(width() - kProductLogo->width() - - kProductLogoPadding, - field_width), - kProductLogoPadding, - product_logo_size.width(), - product_logo_size.height()); -} - -void SearchableUIContainer::Paint(ChromeCanvas* canvas) { - SkColor top_color(kBackground); - canvas->FillRectInt(top_color, 0, 0, - width(), scroll_view_->y()); - - canvas->FillRectInt(kBottomMarginColor, 0, scroll_view_->y() - - kBottomMargin, width(), kBottomMargin); - - canvas->FillRectInt(SkColorSetRGB(196, 196, 196), - 0, scroll_view_->y() - 1, width(), 1); -} - -views::TextField* SearchableUIContainer::GetSearchField() const { - return search_field_; -} - -views::ScrollView* SearchableUIContainer::GetScrollView() const { - return scroll_view_; -} - -void SearchableUIContainer::SetSearchEnabled(bool enabled) { - search_field_->SetReadOnly(!enabled); - search_button_->SetEnabled(enabled); -} - -void SearchableUIContainer::StartThrobber() { - throbber_->Start(); -} - -void SearchableUIContainer::StopThrobber() { - throbber_->Stop(); -} - -void SearchableUIContainer::ButtonPressed(views::NativeButton* sender) { - DoSearch(); -} - -void SearchableUIContainer::LinkActivated(views::Link *link, - int event_flags) { - if (link == title_link_) { - search_field_->SetText(std::wstring()); - DoSearch(); - } -} - -void SearchableUIContainer::HandleKeystroke(views::TextField* sender, - UINT message, - TCHAR key, - UINT repeat_count, - UINT flags) { - if (key == VK_RETURN) - DoSearch(); -} - -void SearchableUIContainer::DoSearch() { - if (delegate_) - delegate_->DoSearch(search_field_->GetText()); - - scroll_view_->ScrollToPosition(scroll_view_->vertical_scroll_bar(), 0); -} - diff --git a/chrome/browser/tab_contents/native_ui_contents.h b/chrome/browser/tab_contents/native_ui_contents.h deleted file mode 100644 index 3982f91..0000000 --- a/chrome/browser/tab_contents/native_ui_contents.h +++ /dev/null @@ -1,295 +0,0 @@ -// Copyright (c) 2006-2008 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. - -#ifndef CHROME_BROWSER_TAB_CONTENTS_NATIVE_UI_CONTENTS_H_ -#define CHROME_BROWSER_TAB_CONTENTS_NATIVE_UI_CONTENTS_H_ - -#include "chrome/browser/page_state.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/views/background.h" -#include "chrome/views/link.h" -#include "chrome/views/native_button.h" -#include "chrome/views/text_field.h" -#include "chrome/views/widget_win.h" - -namespace views { -class CheckBox; -class FocusTraversable; -class ImageView; -class ScrollView; -class Throbber; -} - -class NativeUIFactory; -class NativeUI; - -//////////////////////////////////////////////////////////////////////////////// -// -// NativeUIContents -// -// NativeUIContents is a TabContents that is used to show some pages made with -// some native user interface elements. NativeUIContents maintains a list of URL -// path mapping to specific NativeUI implementations. -// -//////////////////////////////////////////////////////////////////////////////// -class NativeUIContents : public TabContents, - public views::WidgetWin { - public: - explicit NativeUIContents(Profile* profile); - - virtual void CreateView(); - virtual gfx::NativeView GetNativeView() const { return GetHWND(); } - virtual void GetContainerBounds(gfx::Rect* out) const; - - // Sets the page state. NativeUIContents takes ownership of the supplied - // PageState. Use a value of NULL to set the state to empty. - void SetPageState(PageState* page_state); - - // Returns the page state. This is intended for UIs that want to store page - // state. - const PageState& page_state() const { return *state_; } - - // - // TabContents implementation - // - virtual bool NavigateToPendingEntry(bool reload); - virtual const std::wstring GetDefaultTitle() const; - virtual SkBitmap GetFavIcon() const; - virtual bool ShouldDisplayURL() { return false; } - virtual bool ShouldDisplayFavIcon() { return true; } - virtual void DidBecomeSelected(); - virtual void SetInitialFocus(); - - // Sets the current loading state. This is public for NativeUIs to update. - void SetIsLoading(bool is_loading, LoadNotificationDetails* details); - - // FocusTraversable Implementation - virtual views::View* FindNextFocusableView( - views::View* starting_view, - bool reverse, - views::FocusTraversable::Direction direction, - bool dont_loop, - views::FocusTraversable** focus_traversable, - views::View** focus_traversable_view); - virtual views::RootView* GetContentsRootView() { return GetRootView(); } - - // Return the scheme used. We currently use chrome-nativeui: - static std::string GetScheme(); - - // Register a NativeUIFactory for a given path. - static void RegisterNativeUIFactory(const GURL& url, - NativeUIFactory* factory); - - protected: - // Should be deleted via CloseContents. - virtual ~NativeUIContents(); - - // Overridden to create a view that that handles drag and drop. - virtual views::RootView* CreateRootView(); - - private: - // Initialize the factories. This is called the first time a NativeUIContents - // object is created. If you add a new factory, you need to add a line in this - // method. - static void InitializeNativeUIFactories(); - - // Instantiates a native UI for the provided URL. This is done by using the - // native factories which have been registered. - static NativeUI* InstantiateNativeUIForURL(const GURL& url, - NativeUIContents* contents); - - // Returns the key to use based on the TabUI's url. - static std::string GetFactoryKey(const GURL& url); - - // Size the current UI if any. - void Layout(); - - // Return the Native UI for the provided URL. The NativeUIs are returned from - // a cache. Returns NULL if no such UI exists. - NativeUI* GetNativeUIForURL(const GURL& url); - - // Windows message handlers. - virtual LRESULT OnCreate(LPCREATESTRUCT create_struct); - virtual void OnDestroy(); - virtual void OnSize(UINT size_command, const CSize& new_size); - virtual void OnWindowPosChanged(WINDOWPOS* position); - - // Whether this contents is visible. - bool is_visible_; - - // Path to NativeUI map. We keep reusing the same UIs. - typedef std::map<std::string, NativeUI*> PathToUI; - PathToUI path_to_native_uis_; - - // The current UI. - NativeUI* current_ui_; - - // The current view for the current UI. We don't ask again just in case the - // UI implementation keeps allocating new uis. - views::View* current_view_; - - // The current page state for the native contents. - scoped_ptr<PageState> state_; - - // Whether factories have been initialized. - static bool g_ui_factories_initialized; - - DISALLOW_EVIL_CONSTRUCTORS(NativeUIContents); -}; - -///////////////////////////////////////////////////////////////////////////// -// -// A native UI needs to implement the following interface to work with the -// NativeUIContents. -// -///////////////////////////////////////////////////////////////////////////// -class NativeUI { - public: - virtual ~NativeUI() {} - - // Return the title for this user interface. The title is used as a tab title. - virtual const std::wstring GetTitle() const = 0; - - // Return the favicon id for this user interface. - virtual const int GetFavIconID () const = 0; - - // Return the view that should be used to render this user interface. - virtual views::View* GetView() = 0; - - // Inform the view that it is about to become visible. - virtual void WillBecomeVisible(NativeUIContents* parent) = 0; - - // Inform the view that it is about to become invisible. - virtual void WillBecomeInvisible(NativeUIContents* parent) = 0; - - // Inform the view that it should recreate the provided state. The state - // should be updated as needed by using the current navigation entry of - // the provided tab contents. - virtual void Navigate(const PageState& state) = 0; - - // Requests the contents set the initial focus. A return value of true - // indicates the contents wants focus and requested focus. A return value of - // false indicates the contents does not want focus, and that focus should - // go to the location bar. - virtual bool SetInitialFocus() = 0; -}; - -///////////////////////////////////////////////////////////////////////////// -// -// NativeUIFactory defines the method necessary to instantiate a NativeUI -// object. Typically, each NativeUI implementation registers an object that -// can instantiate NativeUI objects given the necessary path. -// -///////////////////////////////////////////////////////////////////////////// -class NativeUIFactory { - public: - virtual ~NativeUIFactory() {} - - // Request the factory to instantiate a NativeUI object given the provided - // url. The url is a nativeui: URL which contains the path for which this - // factory was registered. - // - // See NativeUIContents::RegisterNativeUI(). - virtual NativeUI* CreateNativeUIForURL(const GURL& url, - NativeUIContents* contents) = 0; -}; - - -//////////////////////////////////////////////////////////////////////////////// -// -// A standard background for native UIs. -// -//////////////////////////////////////////////////////////////////////////////// -class NativeUIBackground : public views::Background { - public: - NativeUIBackground(); - virtual ~NativeUIBackground(); - - virtual void Paint(ChromeCanvas* canvas, views::View* view) const; - - private: - - DISALLOW_EVIL_CONSTRUCTORS(NativeUIBackground); -}; - -//////////////////////////////////////////////////////////////////////////////// -// -// A view subclass used to implement native uis that feature a search field. -// This view contains a search field and a ScrollView for the contents. It -// implements a consistent look for these UIs. -// -//////////////////////////////////////////////////////////////////////////////// -class SearchableUIContainer : public views::View, - public views::NativeButton::Listener, - public views::LinkController, - public views::TextField::Controller { - public: - // The Delegate is notified when the user clicks the search button. - class Delegate { - public: - virtual void DoSearch(const std::wstring& text) = 0; - virtual const std::wstring GetTitle() const = 0; - virtual const int GetSectionIconID() const = 0; - virtual const std::wstring GetSearchButtonText() const = 0; - }; - - // Create a new SearchableUIContainer given a delegate. - explicit SearchableUIContainer(Delegate* delegate); - - virtual ~SearchableUIContainer(); - - // Add the view as the contents of the container. - void SetContents(views::View* contents); - views::View* GetContents(); - - virtual void Layout(); - - // Overriden to paint the container. - virtual void Paint(ChromeCanvas* canvas); - - // Provide the mode access to various UI elements. - views::TextField* GetSearchField() const; - views::ScrollView* GetScrollView() const; - - // Enable/disable the search text-field/button. - void SetSearchEnabled(bool enabled); - - // Start and stop the throbber. - void StartThrobber(); - void StopThrobber(); - - private: - // Invoked when the user presses the search button. - virtual void ButtonPressed(views::NativeButton* sender); - - // TextField method, does nothing. - virtual void ContentsChanged(views::TextField* sender, - const std::wstring& new_contents) {} - - // Textfield method, if key is the return key the search is updated. - virtual void HandleKeystroke(views::TextField* sender, - UINT message, - TCHAR key, - UINT repeat_count, - UINT flags); - - // Notifies the delegate to update the search. - void DoSearch(); - - void LinkActivated(views::Link* link, int event_flags); - - Delegate* delegate_; - views::Link* title_link_; - views::ImageView* title_image_; - views::ImageView* product_logo_; - views::TextField* search_field_; - views::NativeButton* search_button_; - views::ScrollView* scroll_view_; - views::Throbber* throbber_; - - DISALLOW_EVIL_CONSTRUCTORS(SearchableUIContainer); -}; - -#endif // CHROME_BROWSER_TAB_CONTENTS_NATIVE_UI_CONTENTS_H_ - diff --git a/chrome/browser/tab_contents/tab_contents_factory.cc b/chrome/browser/tab_contents/tab_contents_factory.cc index 9297eec..0226b4f 100644 --- a/chrome/browser/tab_contents/tab_contents_factory.cc +++ b/chrome/browser/tab_contents/tab_contents_factory.cc @@ -17,7 +17,6 @@ #if defined(OS_WIN) // TODO(port): port these headers to posix. #include "chrome/browser/dom_ui/html_dialog_contents.h" -#include "chrome/browser/tab_contents/native_ui_contents.h" #include "chrome/browser/tab_contents/tab_contents.h" #elif defined(OS_POSIX) #include "chrome/common/temp_scaffolding_stubs.h" @@ -57,9 +56,6 @@ TabContents* TabContents::CreateWithType(TabContentsType type, case TAB_CONTENTS_HTML_DIALOG: contents = new HtmlDialogContents(profile, instance, NULL); break; - case TAB_CONTENTS_NATIVE_UI: - contents = new NativeUIContents(profile); - break; #endif // defined(OS_WIN) case TAB_CONTENTS_DEBUGGER: case TAB_CONTENTS_NEW_TAB_UI: @@ -103,9 +99,6 @@ TabContentsType TabContents::TypeForURL(GURL* url) { if (BrowserURLHandler::HandleBrowserURL(url, &type)) return type; - if (url->SchemeIs(NativeUIContents::GetScheme().c_str())) - return TAB_CONTENTS_NATIVE_UI; - if (HtmlDialogContents::IsHtmlDialogUrl(*url)) return TAB_CONTENTS_HTML_DIALOG; diff --git a/chrome/browser/tab_contents/tab_contents_type.h b/chrome/browser/tab_contents/tab_contents_type.h index 53e79b0..9955258 100644 --- a/chrome/browser/tab_contents/tab_contents_type.h +++ b/chrome/browser/tab_contents/tab_contents_type.h @@ -15,7 +15,6 @@ enum TabContentsType { TAB_CONTENTS_DOWNLOAD_VIEW, TAB_CONTENTS_CHROME_VIEW_CONTENTS, TAB_CONTENTS_NEW_TAB_UI, - TAB_CONTENTS_NATIVE_UI, TAB_CONTENTS_HTML_DIALOG, TAB_CONTENTS_ABOUT_UI, TAB_CONTENTS_DEBUGGER, |