summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/extensions/extension_shelf.h
blob: 57a09540da308d7c645de74cdc8730d74e716396 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2009 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_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_
#define CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_

#include "app/gfx/canvas.h"
#include "base/task.h"
#include "chrome/browser/extensions/extension_shelf_model.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/views/browser_bubble.h"
#include "views/view.h"

class Browser;
namespace views {
  class Label;
  class MouseEvent;
}

// A shelf that contains Extension toolstrips.
class ExtensionShelf : public views::View,
                       public ExtensionContainer,
                       public ExtensionShelfModelObserver {
 public:
  explicit ExtensionShelf(Browser* browser);
  virtual ~ExtensionShelf();

  // Get the current model.
  ExtensionShelfModel* model() { return model_.get(); }

  // View
  virtual void Paint(gfx::Canvas* canvas);
  virtual gfx::Size GetPreferredSize();
  virtual void Layout();
  virtual void OnMouseExited(const views::MouseEvent& event);
  virtual void OnMouseEntered(const views::MouseEvent& event);
  virtual bool GetAccessibleName(std::wstring* name);
  virtual bool GetAccessibleRole(AccessibilityTypes::Role* role);
  virtual void SetAccessibleName(const std::wstring& name);

  // ExtensionContainer
  virtual void OnExtensionMouseEvent(ExtensionView* view);
  virtual void OnExtensionMouseLeave(ExtensionView* view);

  // ExtensionShelfModelObserver
  virtual void ToolstripInsertedAt(ExtensionHost* toolstrip, int index);
  virtual void ToolstripRemovingAt(ExtensionHost* toolstrip, int index);
  virtual void ToolstripDraggingFrom(ExtensionHost* toolstrip, int index);
  virtual void ToolstripMoved(ExtensionHost* toolstrip,
                              int from_index,
                              int to_index);
  virtual void ToolstripChangedAt(ExtensionHost* toolstrip, int index);
  virtual void ExtensionShelfEmpty();
  virtual void ShelfModelReloaded();

 protected:
  // View
  virtual void ChildPreferredSizeChanged(View* child);

 private:
  class Toolstrip;
  friend class Toolstrip;
  class PlaceholderView;

  // Dragging toolstrips
  void DropExtension(Toolstrip* handle, const gfx::Point& pt, bool cancel);

  // Inits the background bitmap.
  void InitBackground(gfx::Canvas* canvas, const SkRect& subset);

  // Returns the Toolstrip at |x| coordinate.  If |x| is out of bounds, returns
  // NULL.
  Toolstrip* ToolstripAtX(int x);

  // Returns the Toolstrip at |index|.
  Toolstrip* ToolstripAtIndex(int index);

  // Returns the toolstrip associated with |view|.
  Toolstrip* ToolstripForView(ExtensionView* view);

  // Loads initial state from |model_|.
  void LoadFromModel();

  // Background bitmap to draw under extension views.
  SkBitmap background_;

  // The model representing the toolstrips on the shelf.
  scoped_ptr<ExtensionShelfModel> model_;

  // Storage of strings needed for accessibility.
  std::wstring accessible_name_;

  DISALLOW_COPY_AND_ASSIGN(ExtensionShelf);
};

#endif  // CHROME_BROWSER_VIEWS_EXTENSIONS_EXTENSION_SHELF_H_