summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/toolbar_view.h
blob: c009dc83e5b49ca9c01c268cbec4ba74d9e6fd17 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// 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_VIEWS_TOOLBAR_VIEW_H__
#define CHROME_BROWSER_VIEWS_TOOLBAR_VIEW_H__

#include <vector>

#include "base/scoped_ptr.h"
#include "chrome/browser/back_forward_menu_model.h"
#include "chrome/browser/controller.h"
#include "chrome/browser/encoding_menu_controller_delegate.h"
#include "chrome/browser/views/dom_view.h"
#include "chrome/browser/views/go_button.h"
#include "chrome/browser/views/location_bar_view.h"
#include "chrome/common/pref_member.h"
#include "chrome/views/menu.h"
#include "chrome/views/menu_button.h"
#include "chrome/views/view.h"
#include "chrome/views/view_menu_delegate.h"

class Browser;
class Profile;
class ToolbarStarToggle;

///////////////////////////////////////////////////////////////////////////////
//
// BrowserToolbarView class
//
//  The BrowserToolbarView is responsible for constructing the content of and
//  rendering the Toolbar used in the Browser Window
//
///////////////////////////////////////////////////////////////////////////////
class BrowserToolbarView : public ChromeViews::View,
                           public EncodingMenuControllerDelegate,
                           public ChromeViews::ViewMenuDelegate,
                           public ChromeViews::DragController,
                           public LocationBarView::Delegate,
                           public NotificationObserver {
 public:
  BrowserToolbarView(CommandController* controller, Browser* browser);
  virtual ~BrowserToolbarView();

  // Create the contents of the Browser Toolbar
  void Init(Profile* profile);

  // ChromeViews::View
  virtual void Layout();
  virtual void DidChangeBounds(const CRect& previous, const CRect& current);
  virtual void DidGainFocus();
  virtual void WillLoseFocus();
  virtual bool OnKeyPressed(const ChromeViews::KeyEvent& e);
  virtual bool OnKeyReleased(const ChromeViews::KeyEvent& e);
  virtual void GetPreferredSize(CSize* out);

  // Overridden from EncodingMenuControllerDelegate:
  virtual bool IsItemChecked(int id) const;

  // Overridden from Menu::BaseControllerDelegate:
  virtual bool GetAcceleratorInfo(int id, ChromeViews::Accelerator* accel);

  // ChromeViews::MenuDelegate
  virtual void RunMenu(ChromeViews::View* source, const CPoint& pt, HWND hwnd);

  // Sets the profile which is active on the currently-active tab.
  void SetProfile(Profile* profile);
  Profile* profile() { return profile_; }

  ToolbarStarToggle* star_button() { return star_; }

  GoButton* GetGoButton() { return go_; }

  LocationBarView* GetLocationBarView() const { return location_bar_; }

  // Updates the toolbar (and transitively the location bar) with the states of
  // the specified |tab|.  If |should_restore_state| is true, we're switching
  // (back?) to this tab and should restore any previous location bar state
  // (such as user editing) as well.
  void Update(TabContents* tab, bool should_restore_state);

  void OnInputInProgress(bool in_progress);

  // Returns the MSAA role of the current view. The role is what assistive
  // technologies (ATs) use to determine what behavior to expect from a given
  // control.
  bool GetAccessibleRole(VARIANT* role);

  // Returns a brief, identifying string, containing a unique, readable name.
  bool GetAccessibleName(std::wstring* name);

  // Assigns an accessible string name.
  void SetAccessibleName(const std::wstring& name);

  // Returns the index of the next view of the toolbar, starting from the given
  // view index (skipping the location bar), in the given navigation direction
  // (nav_left true means navigation right to left, and vice versa). -1 finds
  // first accessible child, based on the above policy.
  int GetNextAccessibleViewIndex(int view_index, bool nav_left);

  ChromeViews::View* GetAccFocusedChildView() {
    return acc_focused_view_;
  }

  // Returns the selected tab.
  virtual TabContents* GetTabContents();

  Browser* browser() { return browser_; }

 private:
  // NotificationObserver
  virtual void Observe(NotificationType type,
                       const NotificationSource& source,
                       const NotificationDetails& details);

  // DragController methods for the star button. These allow the drag if the
  // user hasn't edited the text, the url is valid and should be displayed.
  virtual void WriteDragData(View* sender,
                             int press_x,
                             int press_y,
                             OSExchangeData* data);
  virtual int GetDragOperations(View* sender, int x, int y);

  // Set up the various Views in the toolbar
  void CreateLeftSideControls();
  void CreateCenterStack(Profile* profile);
  void CreateRightSideControls(Profile* profile);

  // Updates the controls to display the security appropriately (highlighted if
  // secure).
  void SetSecurityLevel(ToolbarModel::SecurityLevel security_level);

  // Show the page menu.
  void RunPageMenu(const CPoint& pt, HWND hwnd);

  // Show the app menu.
  void RunAppMenu(const CPoint& pt, HWND hwnd);

  // Types of display mode this toolbar can have.
  enum DisplayMode {
    DISPLAYMODE_NORMAL,
    DISPLAYMODE_LOCATION
  };
  bool IsDisplayModeNormal() const {
    return display_mode_ == DISPLAYMODE_NORMAL;
  }

  // This View's Command Controller
  CommandController* controller_;

  scoped_ptr<BackForwardMenuModel> back_menu_model_;
  scoped_ptr<BackForwardMenuModel> forward_menu_model_;

  // The model that contains the security level, text, icon to display...
  ToolbarModel* model_;

  // Storage of strings needed for accessibility.
  std::wstring accessible_name_;
  // Child view currently having MSAA focus (location bar excluded from arrow
  // navigation).
  ChromeViews::View* acc_focused_view_;

  // Controls
  ChromeViews::Button* back_;
  ChromeViews::Button* forward_;
  ChromeViews::Button* reload_;
  ChromeViews::Button* home_;
  ToolbarStarToggle* star_;
  LocationBarView* location_bar_;
  GoButton* go_;
  ChromeViews::MenuButton* page_menu_;
  ChromeViews::MenuButton* app_menu_;
  Profile* profile_;
  Browser* browser_;

  // Current tab we're showing state for.
  TabContents* tab_;

  // Controls whether or not a home button should be shown on the toolbar.
  BooleanPrefMember show_home_button_;

  // The display mode used when laying out the toolbar.
  DisplayMode display_mode_;
};

#endif  // CHROME_BROWSER_VIEWS_TOOLBAR_VIEW_H__