From 33a85f181bf099afe9067d50277ea0e85e35f302 Mon Sep 17 00:00:00 2001 From: "sky@chromium.org" Date: Tue, 22 Mar 2011 17:54:44 +0000 Subject: Lands http://codereview.chromium.org/2928005/ for Dill: Loads favicons when openning back/forward menu for any urls that don't have favicons. BUG=5679 TEST=Restore a tab with a navigation history, check favicons. Review URL: http://codereview.chromium.org/6708029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79000 0039d316-1c4b-4281-b951-d872f2087c98 --- ui/base/models/menu_model.h | 6 +++++- ui/base/models/menu_model_delegate.h | 22 ++++++++++++++++++++++ ui/base/models/simple_menu_model.cc | 8 +++++++- ui/base/models/simple_menu_model.h | 7 ++++++- 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 ui/base/models/menu_model_delegate.h (limited to 'ui') diff --git a/ui/base/models/menu_model.h b/ui/base/models/menu_model.h index d838a56..9734162 100644 --- a/ui/base/models/menu_model.h +++ b/ui/base/models/menu_model.h @@ -8,6 +8,7 @@ #include "base/scoped_ptr.h" #include "base/string16.h" +#include "ui/base/models/menu_model_delegate.h" #include "ui/gfx/native_widget_types.h" class SkBitmap; @@ -85,7 +86,7 @@ class MenuModel { // Gets the icon for the item at the specified index, returning true if there // is an icon, false otherwise. - virtual bool GetIconAt(int index, SkBitmap* icon) const = 0; + virtual bool GetIconAt(int index, SkBitmap* icon) = 0; // Returns the model for a menu item with a line of buttons at |index|. virtual ButtonMenuItemModel* GetButtonMenuItemAt(int index) const = 0; @@ -116,6 +117,9 @@ class MenuModel { // Called when the menu has been closed. virtual void MenuClosed() {} + // Set the MenuModelDelegate. Owned by the caller of this function. + virtual void SetMenuModelDelegate(MenuModelDelegate* delegate) = 0; + // Retrieves the model and index that contains a specific command id. Returns // true if an item with the specified command id is found. |model| is inout, // and specifies the model to start searching from. diff --git a/ui/base/models/menu_model_delegate.h b/ui/base/models/menu_model_delegate.h new file mode 100644 index 0000000..9516e59 --- /dev/null +++ b/ui/base/models/menu_model_delegate.h @@ -0,0 +1,22 @@ +// Copyright (c) 2010 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 UI_BASE_MODELS_MENU_MODEL_DELEGATE_H_ +#define UI_BASE_MODELS_MENU_MODEL_DELEGATE_H_ +#pragma once + +namespace ui { + +class MenuModelDelegate { + public: + // Invoked when an icon has been loaded from history. + virtual void OnIconChanged(int index) = 0; + + protected: + virtual ~MenuModelDelegate() {} +}; + +} // namespace ui + +#endif // UI_BASE_MODELS_MENU_MODEL_DELEGATE_H_ diff --git a/ui/base/models/simple_menu_model.cc b/ui/base/models/simple_menu_model.cc index 6152766..28c1b01 100644 --- a/ui/base/models/simple_menu_model.cc +++ b/ui/base/models/simple_menu_model.cc @@ -54,6 +54,7 @@ void SimpleMenuModel::Delegate::MenuClosed() { SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate), + menu_model_delegate_(NULL), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { } @@ -245,7 +246,7 @@ int SimpleMenuModel::GetGroupIdAt(int index) const { return items_.at(FlipIndex(index)).group_id; } -bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const { +bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) { if (IsItemDynamicAt(index)) return delegate_->GetIconForCommandId(GetCommandIdAt(index), icon); @@ -299,6 +300,11 @@ void SimpleMenuModel::MenuClosed() { method_factory_.NewRunnableMethod(&SimpleMenuModel::OnMenuClosed)); } +void SimpleMenuModel::SetMenuModelDelegate( + ui::MenuModelDelegate* menu_model_delegate) { + menu_model_delegate_ = menu_model_delegate; +} + void SimpleMenuModel::OnMenuClosed() { if (delegate_) delegate_->MenuClosed(); diff --git a/ui/base/models/simple_menu_model.h b/ui/base/models/simple_menu_model.h index 32490ad..59b752f 100644 --- a/ui/base/models/simple_menu_model.h +++ b/ui/base/models/simple_menu_model.h @@ -112,7 +112,7 @@ class SimpleMenuModel : public MenuModel { ui::Accelerator* accelerator) const; virtual bool IsItemCheckedAt(int index) const; virtual int GetGroupIdAt(int index) const; - virtual bool GetIconAt(int index, SkBitmap* icon) const; + virtual bool GetIconAt(int index, SkBitmap* icon); virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const; virtual bool IsEnabledAt(int index) const; virtual bool IsVisibleAt(int index) const; @@ -120,6 +120,7 @@ class SimpleMenuModel : public MenuModel { virtual void ActivatedAt(int index); virtual MenuModel* GetSubmenuModelAt(int index) const; virtual void MenuClosed(); + virtual void SetMenuModelDelegate(ui::MenuModelDelegate* menu_model_delegate); protected: // Some variants of this model (SystemMenuModel) relies on items to be @@ -131,6 +132,8 @@ class SimpleMenuModel : public MenuModel { Delegate* delegate() { return delegate_; } + MenuModelDelegate* menu_model_delegate() { return menu_model_delegate_; } + private: struct Item; @@ -146,6 +149,8 @@ class SimpleMenuModel : public MenuModel { Delegate* delegate_; + MenuModelDelegate* menu_model_delegate_; + ScopedRunnableMethodFactory method_factory_; DISALLOW_COPY_AND_ASSIGN(SimpleMenuModel); -- cgit v1.1