1// Copyright (c) 2011 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_GTK_CONSTRAINED_WINDOW_GTK_H_
6#define CHROME_BROWSER_UI_GTK_CONSTRAINED_WINDOW_GTK_H_
7#pragma once
8
9#include <gtk/gtk.h>
10
11#include "base/basictypes.h"
12#include "base/task.h"
13#include "chrome/browser/ui/gtk/owned_widget_gtk.h"
14#include "content/browser/tab_contents/constrained_window.h"
15#include "ui/base/gtk/gtk_signal.h"
16
17class TabContents;
18typedef struct _GdkColor GdkColor;
19#if defined(TOUCH_UI)
20class TabContentsViewTouch;
21#else
22class TabContentsViewGtk;
23#endif
24
25class ConstrainedWindowGtkDelegate {
26 public:
27  // Returns the widget that will be put in the constrained window's container.
28  virtual GtkWidget* GetWidgetRoot() = 0;
29
30  // Returns the widget that should get focus when ConstrainedWindow is focused.
31  virtual GtkWidget* GetFocusWidget() = 0;
32
33  // Tells the delegate to either delete itself or set up a task to delete
34  // itself later.
35  virtual void DeleteDelegate() = 0;
36
37  virtual bool GetBackgroundColor(GdkColor* color);
38
39  // Returns true if hosting ConstrainedWindowGtk should apply default padding.
40  virtual bool ShouldHaveBorderPadding() const;
41
42 protected:
43  virtual ~ConstrainedWindowGtkDelegate();
44};
45
46// Constrained window implementation for the GTK port. Unlike the Win32 system,
47// ConstrainedWindowGtk doesn't draw draggable fake windows and instead just
48// centers the dialog. It is thus an order of magnitude simpler.
49class ConstrainedWindowGtk : public ConstrainedWindow {
50 public:
51#if defined(TOUCH_UI)
52   typedef TabContentsViewTouch TabContentsViewType;
53#else
54   typedef TabContentsViewGtk TabContentsViewType;
55#endif
56
57  virtual ~ConstrainedWindowGtk();
58
59  // Overridden from ConstrainedWindow:
60  virtual void ShowConstrainedWindow();
61  virtual void CloseConstrainedWindow();
62  virtual void FocusConstrainedWindow();
63
64  // Returns the TabContents that constrains this Constrained Window.
65  TabContents* owner() const { return owner_; }
66
67  // Returns the toplevel widget that displays this "window".
68  GtkWidget* widget() { return border_.get(); }
69
70  // Returns the View that we collaborate with to position ourselves.
71  TabContentsViewType* ContainingView();
72
73 private:
74  friend class ConstrainedWindow;
75
76  ConstrainedWindowGtk(TabContents* owner,
77                       ConstrainedWindowGtkDelegate* delegate);
78
79  // Signal callbacks.
80  CHROMEGTK_CALLBACK_1(ConstrainedWindowGtk, gboolean, OnKeyPress,
81                       GdkEventKey*);
82  CHROMEGTK_CALLBACK_1(ConstrainedWindowGtk, void, OnHierarchyChanged,
83                       GtkWidget*);
84
85  // The TabContents that owns and constrains this ConstrainedWindow.
86  TabContents* owner_;
87
88  // The top level widget container that exports to our TabContentsView.
89  OwnedWidgetGtk border_;
90
91  // Delegate that provides the contents of this constrained window.
92  ConstrainedWindowGtkDelegate* delegate_;
93
94  // Stores if |ShowConstrainedWindow()| has been called.
95  bool visible_;
96
97  ScopedRunnableMethodFactory<ConstrainedWindowGtk> factory_;
98
99  DISALLOW_COPY_AND_ASSIGN(ConstrainedWindowGtk);
100};
101
102#endif  // CHROME_BROWSER_UI_GTK_CONSTRAINED_WINDOW_GTK_H_
103