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

Side by Side Diff: chrome/browser/extensions/location_bar_controller.h

Issue 10559054: Animate the script badges. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: really sending for review... Created 8 years, 6 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
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 #ifndef CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/observer_list.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "ui/base/animation/linear_animation.h"
17 #include "third_party/skia/include/core/SkBitmap.h"
18
13 class ExtensionAction; 19 class ExtensionAction;
20 class SkDevice;
21
22 namespace ui {
23 class Animation;
24 class AnimationDelegate;
25 }
14 26
15 namespace extensions { 27 namespace extensions {
16 28
17 // Interface for a class that controls the the extension icons that show up in 29 // Interface for a class that controls the the extension icons that show up in
18 // the location bar. Depending on switches, these icons can have differing 30 // the location bar. Depending on switches, these icons can have differing
19 // behavior. 31 // behavior.
20 class LocationBarController { 32 class LocationBarController {
21 public: 33 public:
22 // The reaction that the UI should take after executing |OnClicked|. 34 // The reaction that the UI should take after executing |OnClicked|.
23 enum Action { 35 enum Action {
24 ACTION_NONE, 36 ACTION_NONE,
25 ACTION_SHOW_POPUP, 37 ACTION_SHOW_POPUP,
26 ACTION_SHOW_CONTEXT_MENU, 38 ACTION_SHOW_CONTEXT_MENU,
27 }; 39 };
28 40
41 // A fade-in animation for the items that appear in the locaion bar. These
Yoyo Zhou 2012/06/22 00:50:29 typo: location
not at google - send to devlin 2012/06/26 07:30:47 Done.
42 // are designed to be owned by a LocationBarController (with a tab lifespan),
43 // but used by objects with an unprecictable lifespan in the UI, hence
Yoyo Zhou 2012/06/22 00:50:29 typo: unpredictable
not at google - send to devlin 2012/06/26 07:30:47 Done.
not at google - send to devlin 2012/06/26 07:30:47 Done.
44 // the weak reference support.
45 class IconAnimation : public ui::LinearAnimation,
46 public base::SupportsWeakPtr<IconAnimation> {
47 public:
48 // Observes changes to icon animation state.
49 class Observer {
50 public:
51 virtual void OnIconChanged(const IconAnimation& animation,
52 LocationBarController* location_bar) = 0;
53
54 protected:
55 virtual ~Observer() {}
56 };
57
58 // It's only useful to construct these from LocationBarController
59 // implementations. Use LocationBarController::GetIconAnimation.
60 IconAnimation(LocationBarController* owner,
61 ui::AnimationDelegate* delegate);
62 virtual ~IconAnimation();
63
64 // Returns the icon derived from the current animation state applied to
65 // |icon|. Ownership remains with this.
66 const SkBitmap& Apply(const SkBitmap& icon) const;
67
68 void AddObserver(Observer* observer);
69 void RemoveObserver(Observer* observer);
70
71 private:
72 // ui::LinearAnimation implementation.
73 virtual void AnimateToState(double state) OVERRIDE;
74
75 // Owning LocationBarController to give to observers.
76 LocationBarController* owner_;
77
78 // Device we use to paint icons to.
79 mutable scoped_ptr<SkDevice> device_;
80
81 ObserverList<Observer> observers_;
82
83 DISALLOW_COPY_AND_ASSIGN(IconAnimation);
84 };
85
29 virtual ~LocationBarController() {} 86 virtual ~LocationBarController() {}
30 87
31 // Utility to add any actions to |out| which aren't present in |actions|. 88 // Gets the action data for all extensions.
32 static void AddMissingActions( 89 virtual std::vector<ExtensionAction*> GetCurrentActions() const = 0;
33 const std::set<ExtensionAction*>& actions,
34 std::vector<ExtensionAction*>* out);
35 90
36 // Gets the action data for all extensions. 91 // Gets the icon animation for an ExtensionAction, if there is one.
37 virtual std::vector<ExtensionAction*> GetCurrentActions() = 0; 92 virtual base::WeakPtr<IconAnimation> GetIconAnimation(
93 const ExtensionAction* action) const = 0;
38 94
39 // Notifies this that the badge for an extension has been clicked with some 95 // Notifies this that the badge for an extension has been clicked with some
40 // mouse button (1 for left, 2 for middle, and 3 for right click), and 96 // mouse button (1 for left, 2 for middle, and 3 for right click), and
41 // returns the action that should be taken in response (if any). 97 // returns the action that should be taken in response (if any).
42 // TODO(kalman): make mouse_button an enum. 98 // TODO(kalman): make mouse_button an enum.
43 virtual Action OnClicked(const std::string& extension_id, 99 virtual Action OnClicked(const std::string& extension_id,
44 int mouse_button) = 0; 100 int mouse_button) = 0;
45 }; 101 };
46 102
47 } // namespace extensions 103 } // namespace extensions
48 104
49 #endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_ 105 #endif // CHROME_BROWSER_EXTENSIONS_LOCATION_BAR_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698