| OLD | NEW |
| (Empty) |
| 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 #include "chrome/browser/chromeos/frame/panel_browser_view.h" | |
| 6 | |
| 7 #include "chrome/browser/chromeos/frame/browser_view.h" | |
| 8 #include "chrome/browser/chromeos/frame/panel_controller.h" | |
| 9 #include "third_party/cros_system_api/window_manager/chromeos_wm_ipc_enums.h" | |
| 10 #include "ui/views/widget/widget.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 const int kPanelMinWidthPixels = 100; | |
| 15 const int kPanelMinHeightPixels = 100; | |
| 16 const int kPanelDefaultWidthPixels = 250; | |
| 17 const int kPanelDefaultHeightPixels = 300; | |
| 18 const float kPanelMaxWidthFactor = 0.80; | |
| 19 const float kPanelMaxHeightFactor = 0.80; | |
| 20 | |
| 21 } | |
| 22 | |
| 23 namespace chromeos { | |
| 24 | |
| 25 PanelBrowserView::PanelBrowserView(Browser* browser) | |
| 26 : BrowserView(browser), | |
| 27 creator_xid_(0) { | |
| 28 } | |
| 29 | |
| 30 PanelBrowserView::~PanelBrowserView() {} | |
| 31 | |
| 32 //////////////////////////////////////////////////////////////////////////////// | |
| 33 // PanelBrowserView functions | |
| 34 | |
| 35 void PanelBrowserView::LimitBounds(gfx::Rect* bounds) const { | |
| 36 GdkScreen* screen = gtk_widget_get_screen(GetWidget()->GetNativeView()); | |
| 37 int max_width = gdk_screen_get_width(screen) * kPanelMaxWidthFactor; | |
| 38 int max_height = gdk_screen_get_height(screen) * kPanelMaxHeightFactor; | |
| 39 | |
| 40 if (bounds->width() == 0 && bounds->height() == 0) { | |
| 41 bounds->set_width(kPanelDefaultWidthPixels); | |
| 42 bounds->set_height(kPanelDefaultHeightPixels); | |
| 43 } | |
| 44 | |
| 45 if (bounds->width() < kPanelMinWidthPixels) | |
| 46 bounds->set_width(kPanelMinWidthPixels); | |
| 47 else if (bounds->width() > max_width) | |
| 48 bounds->set_width(max_width); | |
| 49 | |
| 50 if (bounds->height() < kPanelMinHeightPixels) | |
| 51 bounds->set_height(kPanelMinHeightPixels); | |
| 52 else if (bounds->height() > max_height) | |
| 53 bounds->set_height(max_height); | |
| 54 } | |
| 55 | |
| 56 | |
| 57 //////////////////////////////////////////////////////////////////////////////// | |
| 58 // BrowserView overrides. | |
| 59 | |
| 60 void PanelBrowserView::Show() { | |
| 61 InitPanelController(true); // focus when opened | |
| 62 ::BrowserView::Show(); | |
| 63 } | |
| 64 | |
| 65 void PanelBrowserView::ShowInactive() { | |
| 66 InitPanelController(false); | |
| 67 ::BrowserView::ShowInactive(); | |
| 68 } | |
| 69 | |
| 70 void PanelBrowserView::InitPanelController(bool is_active) { | |
| 71 if (panel_controller_.get() == NULL) { | |
| 72 panel_controller_.reset(new PanelController(this, GetNativeHandle())); | |
| 73 panel_controller_->Init( | |
| 74 is_active, bounds(), creator_xid_, | |
| 75 WM_IPC_PANEL_USER_RESIZE_HORIZONTALLY_AND_VERTICALLY); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 void PanelBrowserView::SetBounds(const gfx::Rect& bounds) { | |
| 80 gfx::Rect limit_bounds = bounds; | |
| 81 LimitBounds(&limit_bounds); | |
| 82 ::BrowserView::SetBounds(limit_bounds); | |
| 83 } | |
| 84 | |
| 85 void PanelBrowserView::Close() { | |
| 86 ::BrowserView::Close(); | |
| 87 if (panel_controller_.get()) | |
| 88 panel_controller_->Close(); | |
| 89 } | |
| 90 | |
| 91 void PanelBrowserView::FlashFrame(bool flash) { | |
| 92 if (panel_controller_.get()) | |
| 93 panel_controller_->SetUrgent(flash); | |
| 94 } | |
| 95 | |
| 96 void PanelBrowserView::UpdateTitleBar() { | |
| 97 ::BrowserView::UpdateTitleBar(); | |
| 98 if (panel_controller_.get()) | |
| 99 panel_controller_->UpdateTitleBar(); | |
| 100 } | |
| 101 | |
| 102 bool PanelBrowserView::IsPanel() const { | |
| 103 return true; | |
| 104 } | |
| 105 | |
| 106 void PanelBrowserView::SetCreatorView(PanelBrowserView* creator) { | |
| 107 DCHECK(creator); | |
| 108 GtkWindow* window = creator->GetNativeHandle(); | |
| 109 creator_xid_ = ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window)); | |
| 110 } | |
| 111 | |
| 112 WindowOpenDisposition PanelBrowserView::GetDispositionForPopupBounds( | |
| 113 const gfx::Rect& bounds) { | |
| 114 GdkScreen* screen = gdk_screen_get_default(); | |
| 115 int width = gdk_screen_get_width(screen); | |
| 116 int height = gdk_screen_get_height(screen); | |
| 117 return browser::DispositionForPopupBounds(bounds, width, height); | |
| 118 } | |
| 119 | |
| 120 bool PanelBrowserView::GetSavedWindowPlacement( | |
| 121 gfx::Rect* bounds, | |
| 122 ui::WindowShowState* show_state) const { | |
| 123 bool result = ::BrowserView::GetSavedWindowPlacement(bounds, show_state); | |
| 124 if (result) { | |
| 125 LimitBounds(bounds); | |
| 126 // Panels have no maximized state. | |
| 127 *show_state = ui::SHOW_STATE_NORMAL; | |
| 128 } | |
| 129 return result; | |
| 130 } | |
| 131 | |
| 132 //////////////////////////////////////////////////////////////////////////////// | |
| 133 // views::Widget::Observer overrides. | |
| 134 | |
| 135 void PanelBrowserView::OnWidgetActivationChanged(views::Widget* widget, | |
| 136 bool active) { | |
| 137 ::BrowserView::OnWidgetActivationChanged(widget, active); | |
| 138 if (panel_controller_.get()) { | |
| 139 if (active) | |
| 140 panel_controller_->OnFocusIn(); | |
| 141 else | |
| 142 panel_controller_->OnFocusOut(); | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 //////////////////////////////////////////////////////////////////////////////// | |
| 147 // TabStripModelObserver overrides. | |
| 148 | |
| 149 void PanelBrowserView::TabChangedAt(TabContentsWrapper* contents, | |
| 150 int index, | |
| 151 TabChangeType change_type) { | |
| 152 if (change_type == TabStripModelObserver::TITLE_NOT_LOADING) | |
| 153 panel_controller_->SetUrgent(true); | |
| 154 } | |
| 155 | |
| 156 //////////////////////////////////////////////////////////////////////////////// | |
| 157 // PanelController::Delegate overrides. | |
| 158 | |
| 159 string16 PanelBrowserView::GetPanelTitle() { | |
| 160 return browser()->GetWindowTitleForCurrentTab(); | |
| 161 } | |
| 162 | |
| 163 SkBitmap PanelBrowserView::GetPanelIcon() { | |
| 164 return browser()->GetCurrentPageIcon(); | |
| 165 } | |
| 166 | |
| 167 bool PanelBrowserView::CanClosePanel() { | |
| 168 return ::BrowserView::CanClose(); | |
| 169 } | |
| 170 | |
| 171 void PanelBrowserView::ClosePanel() { | |
| 172 Close(); | |
| 173 } | |
| 174 | |
| 175 void PanelBrowserView::ActivatePanel() { | |
| 176 Activate(); | |
| 177 } | |
| 178 | |
| 179 } // namespace chromeos | |
| OLD | NEW |