Chromium Code Reviews| 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 "ash/shelf/shelf_widget.h" | |
| 6 | |
| 7 #include "ash/focus_cycler.h" | |
| 8 #include "ash/launcher/launcher_delegate.h" | |
| 9 #include "ash/launcher/launcher_model.h" | |
| 10 #include "ash/launcher/launcher_navigator.h" | |
| 11 #include "ash/launcher/launcher_view.h" | |
| 12 #include "ash/root_window_controller.h" | |
| 13 #include "ash/shelf/shelf_layout_manager.h" | |
| 14 #include "ash/shelf/shelf_widget.h" | |
| 15 #include "ash/shell.h" | |
| 16 #include "ash/shell_delegate.h" | |
| 17 #include "ash/shell_window_ids.h" | |
| 18 #include "ash/wm/property_util.h" | |
| 19 #include "ash/wm/status_area_layout_manager.h" | |
| 20 #include "ash/wm/window_properties.h" | |
| 21 #include "ash/wm/workspace_controller.h" | |
| 22 #include "grit/ash_resources.h" | |
| 23 #include "ui/aura/client/activation_client.h" | |
| 24 #include "ui/aura/root_window.h" | |
| 25 #include "ui/aura/window.h" | |
| 26 #include "ui/aura/window_observer.h" | |
| 27 #include "ui/base/resource/resource_bundle.h" | |
| 28 #include "ui/compositor/layer.h" | |
| 29 #include "ui/gfx/canvas.h" | |
| 30 #include "ui/gfx/image/image.h" | |
| 31 #include "ui/gfx/image/image_skia_operations.h" | |
| 32 #include "ui/gfx/skbitmap_operations.h" | |
| 33 #include "ui/views/accessible_pane_view.h" | |
| 34 #include "ui/views/widget/widget.h" | |
| 35 #include "ui/views/widget/widget_delegate.h" | |
| 36 | |
| 37 namespace { | |
| 38 // Size of black border at bottom (or side) of launcher. | |
| 39 const int kNumBlackPixels = 3; | |
| 40 // Alpha to paint dimming image with. | |
| 41 const int kDimAlpha = 96; | |
| 42 } | |
| 43 | |
| 44 namespace ash { | |
| 45 | |
| 46 // The contents view of the Shelf. This view contains LauncherView and | |
| 47 // sizes it to the width of the shelf minus the size of the status area. | |
| 48 class ShelfWidget::DelegateView : public views::WidgetDelegate, | |
| 49 public views::AccessiblePaneView, | |
| 50 public internal::BackgroundAnimatorDelegate { | |
| 51 public: | |
| 52 explicit DelegateView(ShelfWidget* shelf); | |
| 53 virtual ~DelegateView(); | |
| 54 | |
| 55 void set_focus_cycler(internal::FocusCycler* focus_cycler) { | |
| 56 focus_cycler_ = focus_cycler; | |
| 57 } | |
| 58 internal::FocusCycler* focus_cycler() { | |
| 59 return focus_cycler_; | |
| 60 } | |
| 61 | |
| 62 // Set if the shelf area is dimmed (eg when a window is maximized). | |
| 63 void SetDimmed(bool dimmed) { | |
| 64 if (dimmed_ != dimmed) { | |
| 65 dimmed_ = dimmed; | |
| 66 SchedulePaint(); | |
| 67 } | |
| 68 } | |
| 69 bool GetDimmed() const { return dimmed_; } | |
| 70 | |
| 71 // views::View overrides | |
| 72 void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; | |
| 73 | |
| 74 // views::WidgetDelegateView overrides: | |
| 75 views::Widget* GetWidget() OVERRIDE { | |
| 76 return View::GetWidget(); | |
| 77 } | |
| 78 const views::Widget* GetWidget() const OVERRIDE { | |
| 79 return View::GetWidget(); | |
| 80 } | |
| 81 | |
| 82 bool CanActivate() const OVERRIDE { | |
| 83 // Allow to activate as fallback. | |
| 84 if (shelf_->activating_as_fallback_) | |
| 85 return true; | |
| 86 // Allow to activate from the focus cycler. | |
| 87 if (focus_cycler_ && focus_cycler_->widget_activating() == GetWidget()) | |
| 88 return true; | |
| 89 // Disallow activating in other cases, especially when using mouse. | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 void Layout() OVERRIDE { | |
| 94 for(int i = 0; i < this->child_count(); ++i) { | |
| 95 if (shelf_->shelf_layout_manager()->IsHorizontalAlignment()) | |
| 96 child_at(i)->SetBounds(child_at(i)->x(),child_at(i)->y(), | |
| 97 child_at(i)->width(),height()); | |
| 98 else | |
| 99 child_at(i)->SetBounds(child_at(i)->x(),child_at(i)->y(), | |
| 100 width(),child_at(i)->height()); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 // BackgroundAnimatorDelegate overrides: | |
| 105 void UpdateBackground(int alpha) OVERRIDE; | |
| 106 | |
| 107 private: | |
| 108 ShelfWidget* shelf_; | |
| 109 internal::FocusCycler* focus_cycler_; | |
| 110 int alpha_; | |
| 111 bool dimmed_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(DelegateView); | |
| 114 }; | |
| 115 | |
| 116 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) | |
| 117 : shelf_(shelf), | |
| 118 focus_cycler_(NULL), | |
| 119 alpha_(0), | |
| 120 dimmed_(false) { | |
| 121 } | |
| 122 | |
| 123 ShelfWidget::DelegateView::~DelegateView() { | |
| 124 } | |
| 125 | |
| 126 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | |
| 127 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 128 gfx::ImageSkia launcher_background = | |
| 129 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); | |
| 130 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) | |
| 131 launcher_background = gfx::ImageSkiaOperations::CreateRotatedImage( | |
| 132 launcher_background, | |
| 133 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | |
| 134 SkBitmapOperations::ROTATION_90_CW, | |
| 135 SkBitmapOperations::ROTATION_90_CW, | |
| 136 SkBitmapOperations::ROTATION_270_CW, | |
| 137 SkBitmapOperations::ROTATION_180_CW)); | |
| 138 | |
| 139 gfx::Rect black_rect = | |
| 140 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | |
| 141 gfx::Rect(0, height() - kNumBlackPixels, width(), kNumBlackPixels), | |
| 142 gfx::Rect(0, 0, kNumBlackPixels, height()), | |
| 143 gfx::Rect(width() - kNumBlackPixels, 0, kNumBlackPixels, height()), | |
| 144 gfx::Rect(0, 0, width(), kNumBlackPixels)); | |
| 145 | |
| 146 SkPaint paint; | |
| 147 paint.setAlpha(alpha_); | |
| 148 canvas->DrawImageInt( | |
| 149 launcher_background, | |
| 150 0, 0, launcher_background.width(), launcher_background.height(), | |
| 151 0, 0, width(), height(), | |
| 152 false, | |
| 153 paint); | |
| 154 canvas->FillRect(black_rect, SK_ColorBLACK); | |
| 155 | |
| 156 if (dimmed_) { | |
| 157 gfx::ImageSkia background_image = | |
| 158 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_DIMMING); | |
| 159 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) | |
| 160 background_image = gfx::ImageSkiaOperations::CreateRotatedImage( | |
| 161 background_image, | |
| 162 shelf_->shelf_layout_manager()->SelectValueForShelfAlignment( | |
| 163 SkBitmapOperations::ROTATION_90_CW, | |
| 164 SkBitmapOperations::ROTATION_90_CW, | |
| 165 SkBitmapOperations::ROTATION_270_CW, | |
| 166 SkBitmapOperations::ROTATION_180_CW)); | |
| 167 | |
| 168 SkPaint paint; | |
| 169 paint.setAlpha(kDimAlpha); | |
| 170 canvas->DrawImageInt( | |
| 171 background_image, | |
| 172 0, 0, background_image.width(), background_image.height(), | |
| 173 0, 0, width(), height(), | |
| 174 false, | |
| 175 paint); | |
| 176 } | |
| 177 } | |
| 178 | |
| 179 void ShelfWidget::DelegateView::UpdateBackground(int alpha) { | |
| 180 alpha_ = alpha; | |
| 181 SchedulePaint(); | |
| 182 } | |
| 183 | |
| 184 ShelfWidget::ShelfWidget( | |
| 185 aura::Window* shelf_container, | |
| 186 aura::Window* status_container, | |
| 187 internal::WorkspaceController* workspace_controller) : | |
| 188 launcher_(NULL), | |
| 189 delegate_view_(new DelegateView(this)), | |
| 190 background_animator_(delegate_view_, 0, kLauncherBackgroundAlpha), | |
| 191 activating_as_fallback_(false), | |
| 192 window_container_(shelf_container) { | |
| 193 views::Widget::InitParams params( | |
| 194 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 195 params.transparent = true; | |
| 196 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 197 params.parent = shelf_container; | |
| 198 params.delegate = delegate_view_; | |
| 199 Init(params); | |
| 200 | |
| 201 // The shelf should not take focus when initially shown. | |
| 202 set_focus_on_creation(false); | |
| 203 SetContentsView(delegate_view_); | |
| 204 | |
| 205 status_area_widget_ = new internal::StatusAreaWidget(status_container); | |
| 206 status_area_widget_->CreateTrayViews(); | |
| 207 if (Shell::GetInstance()->delegate()->IsSessionStarted()) | |
| 208 status_area_widget_->Show(); | |
| 209 Shell::GetInstance()->focus_cycler()->AddWidget(status_area_widget_); | |
| 210 | |
| 211 shelf_layout_manager_ = new internal::ShelfLayoutManager(this); | |
| 212 shelf_container->SetLayoutManager(shelf_layout_manager_); | |
| 213 shelf_layout_manager_->set_workspace_controller(workspace_controller); | |
| 214 workspace_controller->SetShelf(shelf_layout_manager_); | |
| 215 | |
| 216 status_container->SetLayoutManager( | |
| 217 new internal::StatusAreaLayoutManager(this)); | |
| 218 | |
| 219 views::Widget::AddObserver(this); | |
| 220 } | |
| 221 | |
| 222 ShelfWidget::~ShelfWidget() { | |
| 223 RemoveObserver(this); | |
| 224 } | |
| 225 | |
| 226 void ShelfWidget::SetPaintsBackground( | |
| 227 bool value, | |
| 228 internal::BackgroundAnimator::ChangeType change_type) { | |
| 229 background_animator_.SetPaintsBackground(value, change_type); | |
| 230 } | |
| 231 | |
| 232 ShelfAlignment ShelfWidget::GetAlignment() const { | |
| 233 return shelf_layout_manager_->GetAlignment(); | |
| 234 } | |
| 235 | |
| 236 void ShelfWidget::SetAlignment(ShelfAlignment alignment) { | |
| 237 shelf_layout_manager_->SetAlignment(alignment); | |
| 238 shelf_layout_manager_->LayoutShelf(); | |
| 239 } | |
| 240 | |
| 241 void ShelfWidget::SetDimsShelf(bool dimming) { | |
| 242 delegate_view_->SetDimmed(dimming); | |
| 243 } | |
| 244 | |
| 245 bool ShelfWidget::GetDimsShelf() const { | |
| 246 return delegate_view_->GetDimmed(); | |
| 247 } | |
| 248 | |
| 249 void ShelfWidget::CreateLauncher() { | |
| 250 if (!launcher_.get()) { | |
| 251 // This needs to be called before launcher_model(). | |
| 252 Shell::GetInstance()->GetLauncherDelegate(); | |
| 253 launcher_.reset(new Launcher(Shell::GetInstance()->launcher_model(), | |
| 254 Shell::GetInstance()->GetLauncherDelegate(), | |
| 255 this)); | |
| 256 | |
| 257 SetFocusCycler(Shell::GetInstance()->focus_cycler()); | |
| 258 ShellDelegate* delegate = Shell::GetInstance()->delegate(); | |
| 259 | |
| 260 // Inform the root window controller (for PanelLayoutManager). | |
|
Mr4D (OOO till 08-26)
2013/03/04 19:18:04
Not sure if we should mention that this is for the
Harry McCleave
2013/03/04 20:29:24
Done.
| |
| 261 internal::RootWindowController::ForWindow(window_container_)-> | |
| 262 OnLauncherCreated(); | |
| 263 | |
| 264 if (delegate) | |
| 265 launcher_->SetVisible(delegate->IsSessionStarted()); | |
| 266 | |
| 267 Show(); | |
| 268 } | |
| 269 } | |
| 270 | |
| 271 bool ShelfWidget::LauncherVisible() const { | |
| 272 return launcher_.get() && launcher_->visible(); | |
| 273 } | |
| 274 | |
| 275 void ShelfWidget::SetLauncherVisibility(bool visible) { | |
| 276 if (launcher_.get()) | |
| 277 launcher_->SetVisible(visible); | |
| 278 } | |
| 279 | |
| 280 void ShelfWidget::SetFocusCycler(internal::FocusCycler* focus_cycler) { | |
| 281 delegate_view_->set_focus_cycler(focus_cycler); | |
| 282 if (focus_cycler) | |
| 283 focus_cycler->AddWidget(this); | |
| 284 } | |
| 285 | |
| 286 internal::FocusCycler* ShelfWidget::GetFocusCycler() { | |
| 287 return delegate_view_->focus_cycler(); | |
| 288 } | |
| 289 | |
| 290 void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget, | |
| 291 bool active) { | |
| 292 activating_as_fallback_ = false; | |
| 293 if (active) | |
| 294 delegate_view_->SetPaneFocusAndFocusDefault(); | |
| 295 else | |
| 296 delegate_view_->GetFocusManager()->ClearFocus(); | |
| 297 } | |
| 298 | |
| 299 } // namespace ash | |
| 300 | |
| OLD | NEW |