blob: de39b0e8d2715e2698a12db5b259f4110e56cb1f (
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
|
// Copyright (c) 2011 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.
#include "chrome/browser/chromeos/frame/panel_browser_view.h"
#include "chrome/browser/chromeos/frame/browser_view.h"
#include "chrome/browser/chromeos/frame/panel_controller.h"
#include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h"
#include "views/widget/widget.h"
namespace {
const int kPanelMinWidthPixels = 100;
const int kPanelMinHeightPixels = 100;
const int kPanelDefaultWidthPixels = 250;
const int kPanelDefaultHeightPixels = 300;
const float kPanelMaxWidthFactor = 0.80;
const float kPanelMaxHeightFactor = 0.80;
}
namespace chromeos {
PanelBrowserView::PanelBrowserView(Browser* browser)
: BrowserView(browser),
creator_xid_(0) {
}
PanelBrowserView::~PanelBrowserView() {}
////////////////////////////////////////////////////////////////////////////////
// PanelBrowserView functions
void PanelBrowserView::LimitBounds(gfx::Rect* bounds) const {
GdkScreen* screen = gtk_widget_get_screen(GetWidget()->GetNativeView());
int max_width = gdk_screen_get_width(screen) * kPanelMaxWidthFactor;
int max_height = gdk_screen_get_height(screen) * kPanelMaxHeightFactor;
if (bounds->width() == 0 && bounds->height() == 0) {
bounds->set_width(kPanelDefaultWidthPixels);
bounds->set_height(kPanelDefaultHeightPixels);
}
if (bounds->width() < kPanelMinWidthPixels)
bounds->set_width(kPanelMinWidthPixels);
else if (bounds->width() > max_width)
bounds->set_width(max_width);
if (bounds->height() < kPanelMinHeightPixels)
bounds->set_height(kPanelMinHeightPixels);
else if (bounds->height() > max_height)
bounds->set_height(max_height);
}
////////////////////////////////////////////////////////////////////////////////
// BrowserView overrides.
void PanelBrowserView::Show() {
InitPanelController(true); // focus when opened
::BrowserView::Show();
}
void PanelBrowserView::ShowInactive() {
InitPanelController(false);
::BrowserView::ShowInactive();
}
void PanelBrowserView::InitPanelController(bool is_active) {
if (panel_controller_.get() == NULL) {
panel_controller_.reset(new PanelController(this, GetNativeHandle()));
panel_controller_->Init(
is_active, bounds(), creator_xid_,
WM_IPC_PANEL_USER_RESIZE_HORIZONTALLY_AND_VERTICALLY);
}
}
void PanelBrowserView::SetBounds(const gfx::Rect& bounds) {
gfx::Rect limit_bounds = bounds;
LimitBounds(&limit_bounds);
::BrowserView::SetBounds(limit_bounds);
}
void PanelBrowserView::Close() {
::BrowserView::Close();
if (panel_controller_.get())
panel_controller_->Close();
}
void PanelBrowserView::FlashFrame() {
if (panel_controller_.get())
panel_controller_->SetUrgent(true);
}
void PanelBrowserView::UpdateTitleBar() {
::BrowserView::UpdateTitleBar();
if (panel_controller_.get())
panel_controller_->UpdateTitleBar();
}
void PanelBrowserView::SetCreatorView(PanelBrowserView* creator) {
DCHECK(creator);
GtkWindow* window = creator->GetNativeHandle();
creator_xid_ = ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window));
}
WindowOpenDisposition PanelBrowserView::GetDispositionForPopupBounds(
const gfx::Rect& bounds) {
return chromeos::BrowserView::DispositionForPopupBounds(bounds);
}
bool PanelBrowserView::GetSavedWindowPlacement(
gfx::Rect* bounds,
ui::WindowShowState* show_state) const {
bool result = ::BrowserView::GetSavedWindowPlacement(bounds, show_state);
if (result) {
LimitBounds(bounds);
// Panels have no maximized state.
*show_state = ui::SHOW_STATE_NORMAL;
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
// views::Widget::Observer overrides.
void PanelBrowserView::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
::BrowserView::OnWidgetActivationChanged(widget, active);
if (panel_controller_.get()) {
if (active)
panel_controller_->OnFocusIn();
else
panel_controller_->OnFocusOut();
}
}
////////////////////////////////////////////////////////////////////////////////
// TabStripModelObserver overrides.
void PanelBrowserView::TabChangedAt(TabContentsWrapper* contents,
int index,
TabChangeType change_type) {
if (change_type == TabStripModelObserver::TITLE_NOT_LOADING)
panel_controller_->SetUrgent(true);
}
////////////////////////////////////////////////////////////////////////////////
// PanelController::Delegate overrides.
string16 PanelBrowserView::GetPanelTitle() {
return browser()->GetWindowTitleForCurrentTab();
}
SkBitmap PanelBrowserView::GetPanelIcon() {
return browser()->GetCurrentPageIcon();
}
bool PanelBrowserView::CanClosePanel() {
return ::BrowserView::CanClose();
}
void PanelBrowserView::ClosePanel() {
Close();
}
void PanelBrowserView::ActivatePanel() {
Activate();
}
} // namespace chromeos
|