summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views/app_launcher.h
blob: 1472f064c20cbbd7b3f43cb8e6ba1dda8c70f822 (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
// 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 CHROME_BROWSER_VIEWS_APP_LAUNCHER_H_
#define CHROME_BROWSER_VIEWS_APP_LAUNCHER_H_

#include "base/scoped_ptr.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/browser/views/pinned_contents_info_bubble.h"
#include "views/view.h"

class Browser;
class SiteInstance;

namespace gfx {
class Size;
}
namespace views {
class NativeViewHost;
class View;
class WidgetGtk;
}

class InfoBubbleContentsView;
class NavigationBar;
class TabContentsDelegateImpl;

// AppLauncher manages showing the application launcher and optionally the
// navigation bar in compact navigation bar mode. The app launcher is
// currently an HTML page. When the user clicks a link on the page a
// new tab is added to the current browser and the app launcher is hidden.
// When the user opens a new page from the navigation bar, it opens a
// new tab on left, on right or clobbers the current tab depending on
// the configuration.
//
// To show the app launcher invoke Show.
//
// When a new url is opened, or the user clicks outsides the bounds of the
// widget the app launcher is closed.
class AppLauncher : public InfoBubbleDelegate,
                    public TabContentsDelegate {
 public:
  // Shows an application launcher bubble pointing to the |bounds| (which should
  // be in screen coordinates). |bubble_anchor| specifies at which coordinates
  // the bubble contents should appear (in screen coordinates). The bubble will
  // be moved accordingly.
  // The caller DOES NOT OWN the AppLauncher returned.  It is deleted
  // automatically when the AppLauncher is closed.
  static AppLauncher* Show(Browser* browser,
                           const gfx::Rect& bounds,
                           const gfx::Point& bubble_anchor);

  // Shows an application launcher bubble pointing to the new tab button.
  // The caller DOES NOT OWN the AppLauncher returned.  It is deleted
  // automatically when the AppLauncher is closed.
  static AppLauncher* ShowForNewTab(Browser* browser);

  // Returns the browser this AppLauncher is associated with.
  Browser* browser() const { return browser_; }

  // Hides the app launcher.
  void Hide();

  // InfoBubbleDelegate overrides.
  virtual void InfoBubbleClosing(InfoBubble* info_bubble,
                                 bool closed_by_escape);
  virtual bool CloseOnEscape() { return true; }

  // TabContentsDelegate.
  virtual void OpenURLFromTab(TabContents* source,
                              const GURL& url, const GURL& referrer,
                              WindowOpenDisposition disposition,
                              PageTransition::Type transition);
  virtual void NavigationStateChanged(const TabContents* source,
                                      unsigned changed_flags) {}
  virtual void AddNewContents(TabContents* source,
                              TabContents* new_contents,
                              WindowOpenDisposition disposition,
                              const gfx::Rect& initial_pos,
                              bool user_gesture);
  virtual void ActivateContents(TabContents* contents) {}
  virtual void LoadingStateChanged(TabContents* source) {}
  virtual void CloseContents(TabContents* source) {}
  virtual void MoveContents(TabContents* source, const gfx::Rect& pos) {}
  virtual bool IsPopup(TabContents* source) { return false; }
  virtual void ToolbarSizeChanged(TabContents* source, bool is_animating) {}
  virtual void URLStarredChanged(TabContents* source, bool starred) {}
  virtual void UpdateTargetURL(TabContents* source, const GURL& url) {}

 private:
  friend class DeleteTask<AppLauncher>;
  friend class NavigationBar;
  friend class InfoBubbleContentsView;

  explicit AppLauncher(Browser* browser);
  ~AppLauncher();

  void AddTabWithURL(const GURL& url, PageTransition::Type transition);

  // The currently active browser. We use this to open urls.
  Browser* browser_;

  // The InfoBubble displaying the Omnibox and app contents.
  PinnedContentsInfoBubble* info_bubble_;

  // The view with the navigation bar and render view, shown in the info-bubble.
  InfoBubbleContentsView* info_bubble_content_;

  DISALLOW_COPY_AND_ASSIGN(AppLauncher);
};

#endif  // CHROME_BROWSER_VIEWS_APP_LAUNCHER_H_