browser_root_view.h revision 116680a4aac90f2aa7413d9095a592090648e557
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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_ROOT_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_ROOT_VIEW_H_
7
8#include "ui/views/widget/root_view.h"
9
10class BrowserView;
11class TabStrip;
12
13namespace ui {
14class OSExchangeData;
15}
16
17// RootView implementation used by BrowserFrame. This forwards drop events to
18// the TabStrip. Visually the tabstrip extends to the top of the frame, but in
19// actually it doesn't. The tabstrip is only as high as a tab. To enable
20// dropping above the tabstrip BrowserRootView forwards drop events to the
21// TabStrip.
22class BrowserRootView : public views::internal::RootView {
23 public:
24  // Internal class name.
25  static const char kViewClassName[];
26
27  // You must call set_tabstrip before this class will accept drops.
28  BrowserRootView(BrowserView* browser_view, views::Widget* widget);
29
30  // Overridden from views::View:
31  virtual bool GetDropFormats(
32      int* formats,
33      std::set<ui::OSExchangeData::CustomFormat>* custom_formats) OVERRIDE;
34  virtual bool AreDropTypesRequired() OVERRIDE;
35  virtual bool CanDrop(const ui::OSExchangeData& data) OVERRIDE;
36  virtual void OnDragEntered(const ui::DropTargetEvent& event) OVERRIDE;
37  virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE;
38  virtual void OnDragExited() OVERRIDE;
39  virtual int OnPerformDrop(const ui::DropTargetEvent& event) OVERRIDE;
40  virtual const char* GetClassName() const OVERRIDE;
41  virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE;
42
43 private:
44  // ui::EventProcessor:
45  virtual ui::EventDispatchDetails OnEventFromSource(ui::Event* event) OVERRIDE;
46
47  // Returns true if the event should be forwarded to the tabstrip.
48  bool ShouldForwardToTabStrip(const ui::DropTargetEvent& event);
49
50  // Converts the event from the hosts coordinate system to the tabstrips
51  // coordinate system.
52  ui::DropTargetEvent* MapEventToTabStrip(
53      const ui::DropTargetEvent& event,
54      const ui::OSExchangeData& data);
55
56  inline TabStrip* tabstrip() const;
57
58  // Returns true if |data| has string contents and the user can "paste and go".
59  // If |url| is non-NULL and the user can "paste and go", |url| is set to the
60  // desired destination.
61  bool GetPasteAndGoURL(const ui::OSExchangeData& data, GURL* url);
62
63  // The BrowserView.
64  BrowserView* browser_view_;
65
66  // If true, drag and drop events are being forwarded to the tab strip.
67  // This is used to determine when to send OnDragEntered and OnDragExited
68  // to the tab strip.
69  bool forwarding_to_tab_strip_;
70
71  DISALLOW_COPY_AND_ASSIGN(BrowserRootView);
72};
73
74#endif  // CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_ROOT_VIEW_H_
75