summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/panels/panel_browser_window.cc
blob: e839497769a86e3b83f433333849d622da1cdc11 (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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
// Copyright (c) 2012 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/ui/panels/panel_browser_window.h"

#include "base/logging.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/panels/panel.h"
#include "chrome/browser/ui/panels/native_panel.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/window_sizer.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/rect.h"

#if defined(USE_AURA)
#include "chrome/browser/ui/panels/panel_browser_view.h"
#endif

using content::NativeWebKeyboardEvent;
using content::SSLStatus;
using content::WebContents;

PanelBrowserWindow::PanelBrowserWindow(Browser* browser, Panel* panel,
                                       NativePanel* native_panel)
    : browser_(browser),
      panel_(panel),
      native_panel_(native_panel) {
  browser_->tab_strip_model()->AddObserver(this);
}

PanelBrowserWindow::~PanelBrowserWindow() {
  browser_->tab_strip_model()->RemoveObserver(this);
  // Invoked by native panel destructor via panel destructor.
  // Do not access native_panel_ nor panel_ here.
}

// ----------------------------------------------
// BaseWindow interface - just delegates to Panel
// ----------------------------------------------
bool PanelBrowserWindow::IsActive() const {
  return panel_->IsActive();
}

bool PanelBrowserWindow::IsMaximized() const {
  return panel_->IsMaximized();
}

bool PanelBrowserWindow::IsMinimized() const {
  return panel_->IsMinimized();
}

bool PanelBrowserWindow::IsFullscreen() const {
  return panel_->IsFullscreen();
}

gfx::Rect PanelBrowserWindow::GetRestoredBounds() const {
  return panel_->GetRestoredBounds();
}

gfx::Rect PanelBrowserWindow::GetBounds() const {
  return panel_->GetBounds();
}

void PanelBrowserWindow::Show() {
  panel_->Show();
}

void PanelBrowserWindow::ShowInactive() {
  panel_->ShowInactive();
}

void PanelBrowserWindow::Close() {
  panel_->Close();
}

void PanelBrowserWindow::Activate() {
  panel_->Activate();
}

void PanelBrowserWindow::Deactivate() {
  panel_->Deactivate();
}

void PanelBrowserWindow::Maximize() {
  panel_->Maximize();
}

void PanelBrowserWindow::Minimize() {
  panel_->Minimize();
}

void PanelBrowserWindow::Restore() {
  panel_->Restore();
}

void PanelBrowserWindow::SetBounds(const gfx::Rect& bounds) {
  panel_->SetBounds(bounds);
}

void PanelBrowserWindow::SetDraggableRegion(SkRegion* region) {
  panel_->SetDraggableRegion(region);
}

void PanelBrowserWindow::FlashFrame(bool flash) {
  panel_->FlashFrame(flash);
}

bool PanelBrowserWindow::IsAlwaysOnTop() const {
  return panel_->IsAlwaysOnTop();
}

// ------------------------------------------------------------
// BrowserWindow interface - either does nothing, delegates to
// native panel, delegates to Panel (WebContents handling)
// or invoke logic that has nothing to do with panels (GetDownloadShelf).
// -----------------------------------------------------------
gfx::NativeWindow PanelBrowserWindow::GetNativeHandle() {
  return native_panel_->GetNativePanelHandle();
}

BrowserWindowTesting* PanelBrowserWindow::GetBrowserWindowTesting() {
  NOTIMPLEMENTED();
  return NULL;
}

StatusBubble* PanelBrowserWindow::GetStatusBubble() {
  // TODO(jennb): Implement. http://crbug.com/102723
  return NULL;
}

void PanelBrowserWindow::ToolbarSizeChanged(bool is_animating) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::UpdateTitleBar() {
  native_panel_->UpdatePanelTitleBar();
}

void PanelBrowserWindow::BookmarkBarStateChanged(
    BookmarkBar::AnimateChangeType change_type) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::UpdateDevTools() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::SetDevToolsDockSide(DevToolsDockSide side) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::UpdateLoadingAnimations(bool should_animate) {
  native_panel_->UpdatePanelLoadingAnimations(should_animate);
}

void PanelBrowserWindow::SetStarredState(bool is_starred) {
  // Since panels are typically not bookmarked extension UI windows, they don't
  // have starred state.
}

void PanelBrowserWindow::EnterFullscreen(
      const GURL& url, FullscreenExitBubbleType type) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ExitFullscreen() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::UpdateFullscreenExitBubbleContent(
      const GURL& url,
      FullscreenExitBubbleType bubble_type) {
  NOTIMPLEMENTED();
}

bool PanelBrowserWindow::IsFullscreenBubbleVisible() const {
  NOTIMPLEMENTED();
  return false;
}

LocationBar* PanelBrowserWindow::GetLocationBar() const {
#if defined(USE_AURA)
  // TODO(stevenjb): Remove this when Aura panels are implemented post R18.
  PanelBrowserView* panel_view = static_cast<PanelBrowserView*>(native_panel_);
  return panel_view->GetLocationBar();
#else
  // Panels do not have a location bar.
  return NULL;
#endif
}

void PanelBrowserWindow::SetFocusToLocationBar(bool select_all) {
#if defined(USE_AURA)
  // TODO(stevenjb): Remove this when Aura panels are implemented post R18.
  PanelBrowserView* panel_view = static_cast<PanelBrowserView*>(native_panel_);
  panel_view->SetFocusToLocationBar(select_all);
#else
  // Panels do not have a location bar.
#endif
}

void PanelBrowserWindow::UpdateReloadStopState(bool is_loading, bool force) {
  // Panels don't have stop/reload indicator.
}

void PanelBrowserWindow::UpdateToolbar(TabContentsWrapper* contents,
                                       bool should_restore_state) {
  // Panels do not have a toolbar.
}

void PanelBrowserWindow::FocusToolbar() {
  // Panels do not have a toolbar.
}

void PanelBrowserWindow::FocusAppMenu() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::FocusBookmarksToolbar() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::RotatePaneFocus(bool forwards) {
  NOTIMPLEMENTED();
}

bool PanelBrowserWindow::IsBookmarkBarVisible() const {
  return false;
}

bool PanelBrowserWindow::IsBookmarkBarAnimating() const {
  return false;
}

// This is used by extensions to decide if a window can be closed.
// Always return true as panels do not have tabs that can be dragged,
// during which extensions will avoid closing a window.
bool PanelBrowserWindow::IsTabStripEditable() const {
  return true;
}

bool PanelBrowserWindow::IsToolbarVisible() const {
  NOTIMPLEMENTED();
  return false;
}

gfx::Rect PanelBrowserWindow::GetRootWindowResizerRect() const {
  return gfx::Rect();
}

bool PanelBrowserWindow::IsPanel() const {
  return true;
}

void PanelBrowserWindow::DisableInactiveFrame() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ConfirmAddSearchProvider(TemplateURL* template_url,
                                                  Profile* profile) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ToggleBookmarkBar() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ShowAboutChromeDialog() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ShowUpdateChromeDialog() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ShowTaskManager() {
  native_panel_->ShowTaskManagerForPanel();
}

void PanelBrowserWindow::ShowBackgroundPages() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ShowBookmarkBubble(const GURL& url,
                                            bool already_bookmarked) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ShowChromeToMobileBubble() {
  NOTIMPLEMENTED();
}

#if defined(ENABLE_ONE_CLICK_SIGNIN)
void PanelBrowserWindow::ShowOneClickSigninBubble(
      const StartSyncCallback& start_sync_callback) {
  NOTIMPLEMENTED();
}
#endif

bool PanelBrowserWindow::IsDownloadShelfVisible() const {
  return false;
}

DownloadShelf* PanelBrowserWindow::GetDownloadShelf() {
  Profile* profile = browser_->profile();
  Browser* tabbed_browser = browser::FindTabbedBrowser(profile, true);

  if (!tabbed_browser) {
    // Set initial bounds so window will not be positioned at an offset
    // to this panel as panels are at the bottom of the screen.
    gfx::Rect window_bounds;
    WindowSizer::GetBrowserWindowBounds(std::string(), gfx::Rect(),
                                        browser_, &window_bounds);
    Browser::CreateParams params(Browser::TYPE_TABBED, profile);
    params.initial_bounds = window_bounds;
    tabbed_browser = Browser::CreateWithParams(params);
    tabbed_browser->NewTab();
  }

  tabbed_browser->window()->Show();  // Ensure download shelf is visible.
  return tabbed_browser->window()->GetDownloadShelf();
}

void PanelBrowserWindow::ConfirmBrowserCloseWithPendingDownloads() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::UserChangedTheme() {
  native_panel_->NotifyPanelOnUserChangedTheme();
}

int PanelBrowserWindow::GetExtraRenderViewHeight() const {
  // This is currently used only on Linux and that returns the height for
  // optional elements like bookmark bar, download bar etc.  Not applicable to
  // panels.
  return 0;
}

void PanelBrowserWindow::WebContentsFocused(WebContents* contents) {
  native_panel_->PanelWebContentsFocused(contents);
}

void PanelBrowserWindow::ShowPageInfo(Profile* profile,
                                      const GURL& url,
                                      const SSLStatus& ssl,
                                      bool show_history) {
  NOTIMPLEMENTED();
}
void PanelBrowserWindow::ShowWebsiteSettings(
    Profile* profile,
    TabContentsWrapper* tab_contents_wrapper,
    const GURL& url,
    const content::SSLStatus& ssl,
    bool show_history) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ShowAppMenu() {
  NOTIMPLEMENTED();
}

bool PanelBrowserWindow::PreHandleKeyboardEvent(
    const content::NativeWebKeyboardEvent& event,
    bool* is_keyboard_shortcut) {
  return native_panel_->PreHandlePanelKeyboardEvent(event,
                                                    is_keyboard_shortcut);
}

void PanelBrowserWindow::HandleKeyboardEvent(
    const content::NativeWebKeyboardEvent& event) {
  native_panel_->HandlePanelKeyboardEvent(event);
}

void PanelBrowserWindow::ShowCreateWebAppShortcutsDialog(
    TabContentsWrapper* tab_contents) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ShowCreateChromeAppShortcutsDialog(
    Profile* profile,
    const extensions::Extension* app) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::Cut() {
  native_panel_->PanelCut();
}

void PanelBrowserWindow::Copy() {
  native_panel_->PanelCopy();
}

void PanelBrowserWindow::Paste() {
  native_panel_->PanelPaste();
}

#if defined(OS_MACOSX)
void PanelBrowserWindow::OpenTabpose() {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::EnterPresentationMode(
      const GURL& url,
      FullscreenExitBubbleType content_type) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::ExitPresentationMode() {
  NOTIMPLEMENTED();
}

bool PanelBrowserWindow::InPresentationMode() {
  NOTIMPLEMENTED();
  return false;
}
#endif

void PanelBrowserWindow::ShowInstant(TabContentsWrapper* preview) {
  NOTIMPLEMENTED();
}

void PanelBrowserWindow::HideInstant() {
  NOTIMPLEMENTED();
}

gfx::Rect PanelBrowserWindow::GetInstantBounds() {
  NOTIMPLEMENTED();
  return gfx::Rect();
}

WindowOpenDisposition PanelBrowserWindow::GetDispositionForPopupBounds(
    const gfx::Rect& bounds) {
#if defined(USE_AURA)
  // TODO(stevenjb): Remove this when Aura panels are implemented post R18.
  PanelBrowserView* panel_view = static_cast<PanelBrowserView*>(native_panel_);
  return panel_view->GetDispositionForPopupBounds(bounds);
#else
  return NEW_POPUP;
#endif
}

FindBar* PanelBrowserWindow::CreateFindBar() {
  return native_panel_->CreatePanelFindBar();
}

void PanelBrowserWindow::ResizeDueToAutoResize(WebContents* web_contents,
                                               const gfx::Size& pref_size) {
  DCHECK(panel_->auto_resizable());
  return panel_->OnWindowAutoResized(
      native_panel_->WindowSizeFromContentSize(pref_size));
}

void PanelBrowserWindow::ShowAvatarBubble(WebContents* web_contents,
                                          const gfx::Rect& rect) {
  // Panels will never show a new tab page so this should never be called.
  NOTREACHED();
}

void PanelBrowserWindow::ShowAvatarBubbleFromAvatarButton() {
  // Panels will never show an avatar button so this should never be called.
  NOTREACHED();
}

void PanelBrowserWindow::DestroyBrowser() {
  native_panel_->DestroyPanelBrowser();
}

void PanelBrowserWindow::TabInsertedAt(TabContentsWrapper* contents,
                                       int index,
                                       bool foreground) {
  if (panel_->auto_resizable()) {
    DCHECK_EQ(0, index);
    panel_->EnableWebContentsAutoResize(contents->web_contents());
  }
}