| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 hot_painter_(CreatePainter(SkColorSetRGB(0xA0, 0xA0, 0xA0), | 56 hot_painter_(CreatePainter(SkColorSetRGB(0xA0, 0xA0, 0xA0), |
| 57 SkColorSetRGB(0xD0, 0xD0, 0xD0))), | 57 SkColorSetRGB(0xD0, 0xD0, 0xD0))), |
| 58 pushed_painter_(CreatePainter(SkColorSetRGB(0x80, 0x80, 0x80), | 58 pushed_painter_(CreatePainter(SkColorSetRGB(0x80, 0x80, 0x80), |
| 59 SkColorSetRGB(0x90, 0x90, 0x90))), | 59 SkColorSetRGB(0x90, 0x90, 0x90))), |
| 60 insets_(2, 6, 2, 6) { | 60 insets_(2, 6, 2, 6) { |
| 61 } | 61 } |
| 62 virtual ~CustomButtonBorder() {} | 62 virtual ~CustomButtonBorder() {} |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 // Overridden from views::Border: | 65 // Overridden from views::Border: |
| 66 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE { | 66 virtual void Paint(const views::View& view, gfx::Canvas* canvas) override { |
| 67 const views::LabelButton* button = | 67 const views::LabelButton* button = |
| 68 static_cast<const views::LabelButton*>(&view); | 68 static_cast<const views::LabelButton*>(&view); |
| 69 views::Button::ButtonState state = button->state(); | 69 views::Button::ButtonState state = button->state(); |
| 70 | 70 |
| 71 views::Painter* painter = normal_painter_.get(); | 71 views::Painter* painter = normal_painter_.get(); |
| 72 if (state == views::Button::STATE_HOVERED) { | 72 if (state == views::Button::STATE_HOVERED) { |
| 73 painter = hot_painter_.get(); | 73 painter = hot_painter_.get(); |
| 74 } else if (state == views::Button::STATE_PRESSED) { | 74 } else if (state == views::Button::STATE_PRESSED) { |
| 75 painter = pushed_painter_.get(); | 75 painter = pushed_painter_.get(); |
| 76 } | 76 } |
| 77 painter->Paint(canvas, view.size()); | 77 painter->Paint(canvas, view.size()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual gfx::Insets GetInsets() const OVERRIDE { | 80 virtual gfx::Insets GetInsets() const override { |
| 81 return insets_; | 81 return insets_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 virtual gfx::Size GetMinimumSize() const OVERRIDE { | 84 virtual gfx::Size GetMinimumSize() const override { |
| 85 gfx::Size size; | 85 gfx::Size size; |
| 86 if (normal_painter_) | 86 if (normal_painter_) |
| 87 size.SetToMax(normal_painter_->GetMinimumSize()); | 87 size.SetToMax(normal_painter_->GetMinimumSize()); |
| 88 if (hot_painter_) | 88 if (hot_painter_) |
| 89 size.SetToMax(hot_painter_->GetMinimumSize()); | 89 size.SetToMax(hot_painter_->GetMinimumSize()); |
| 90 if (pushed_painter_) | 90 if (pushed_painter_) |
| 91 size.SetToMax(pushed_painter_->GetMinimumSize()); | 91 size.SetToMax(pushed_painter_->GetMinimumSize()); |
| 92 return size; | 92 return size; |
| 93 } | 93 } |
| 94 | 94 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 params.delegate = widget_delegate; | 164 params.delegate = widget_delegate; |
| 165 params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height()); | 165 params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height()); |
| 166 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; | 166 params.opacity = views::Widget::InitParams::OPAQUE_WINDOW; |
| 167 widget->Init(params); | 167 widget->Init(params); |
| 168 widget->Show(); | 168 widget->Show(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 private: | 171 private: |
| 172 // Overridden from views::ButtonListener: | 172 // Overridden from views::ButtonListener: |
| 173 virtual void ButtonPressed(views::Button* sender, | 173 virtual void ButtonPressed(views::Button* sender, |
| 174 const ui::Event& event) OVERRIDE { | 174 const ui::Event& event) override { |
| 175 for (int i = 0; i < CONTROL_COUNT; ++i) { | 175 for (int i = 0; i < CONTROL_COUNT; ++i) { |
| 176 if (sender == buttons_[i]) { | 176 if (sender == buttons_[i]) { |
| 177 delegate_->ButtonPressed(static_cast<ControlType>(i)); | 177 delegate_->ButtonPressed(static_cast<ControlType>(i)); |
| 178 return; | 178 return; |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 Delegate* delegate_; | 183 Delegate* delegate_; |
| 184 views::Button* buttons_[CONTROL_COUNT]; | 184 views::Button* buttons_[CONTROL_COUNT]; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 205 virtual ~MediaViewer() { | 205 virtual ~MediaViewer() { |
| 206 if (root_view_) | 206 if (root_view_) |
| 207 root_view_->RemoveObserver(this); | 207 root_view_->RemoveObserver(this); |
| 208 } | 208 } |
| 209 | 209 |
| 210 private: | 210 private: |
| 211 typedef std::map<std::string, std::string> HandlerMap; | 211 typedef std::map<std::string, std::string> HandlerMap; |
| 212 | 212 |
| 213 | 213 |
| 214 // Overridden from ApplicationDelegate: | 214 // Overridden from ApplicationDelegate: |
| 215 virtual void Initialize(ApplicationImpl* app) OVERRIDE { | 215 virtual void Initialize(ApplicationImpl* app) override { |
| 216 view_manager_client_factory_.reset( | 216 view_manager_client_factory_.reset( |
| 217 new ViewManagerClientFactory(app->shell(), this)); | 217 new ViewManagerClientFactory(app->shell(), this)); |
| 218 app_ = app; | 218 app_ = app; |
| 219 views_init_.reset(new ViewsInit); | 219 views_init_.reset(new ViewsInit); |
| 220 } | 220 } |
| 221 | 221 |
| 222 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) | 222 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) |
| 223 OVERRIDE { | 223 override { |
| 224 connection->AddService(view_manager_client_factory_.get()); | 224 connection->AddService(view_manager_client_factory_.get()); |
| 225 return true; | 225 return true; |
| 226 } | 226 } |
| 227 | 227 |
| 228 void LayoutViews() { | 228 void LayoutViews() { |
| 229 View* root = content_view_->parent(); | 229 View* root = content_view_->parent(); |
| 230 gfx::Rect control_bounds(root->bounds().width(), 28); | 230 gfx::Rect control_bounds(root->bounds().width(), 28); |
| 231 control_view_->SetBounds(control_bounds); | 231 control_view_->SetBounds(control_bounds); |
| 232 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), | 232 gfx::Rect content_bounds(0, control_bounds.height(), root->bounds().width(), |
| 233 root->bounds().height() - control_bounds.height()); | 233 root->bounds().height() - control_bounds.height()); |
| 234 content_view_->SetBounds(content_bounds); | 234 content_view_->SetBounds(content_bounds); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // Overridden from ViewManagerDelegate: | 237 // Overridden from ViewManagerDelegate: |
| 238 virtual void OnEmbed(ViewManager* view_manager, | 238 virtual void OnEmbed(ViewManager* view_manager, |
| 239 View* root, | 239 View* root, |
| 240 ServiceProviderImpl* exported_services, | 240 ServiceProviderImpl* exported_services, |
| 241 scoped_ptr<ServiceProvider> imported_services) OVERRIDE { | 241 scoped_ptr<ServiceProvider> imported_services) override { |
| 242 root_view_ = root; | 242 root_view_ = root; |
| 243 view_manager_ = view_manager; | 243 view_manager_ = view_manager; |
| 244 | 244 |
| 245 control_view_ = View::Create(view_manager_); | 245 control_view_ = View::Create(view_manager_); |
| 246 root_view_->AddChild(control_view_); | 246 root_view_->AddChild(control_view_); |
| 247 | 247 |
| 248 content_view_ = View::Create(view_manager_); | 248 content_view_ = View::Create(view_manager_); |
| 249 root_view_->AddChild(content_view_); | 249 root_view_->AddChild(content_view_); |
| 250 | 250 |
| 251 control_panel_.Initialize(control_view_); | 251 control_panel_.Initialize(control_view_); |
| 252 | 252 |
| 253 LayoutViews(); | 253 LayoutViews(); |
| 254 root_view_->AddObserver(this); | 254 root_view_->AddObserver(this); |
| 255 | 255 |
| 256 content_view_->Embed("TODO"); | 256 content_view_->Embed("TODO"); |
| 257 } | 257 } |
| 258 | 258 |
| 259 virtual void OnViewManagerDisconnected( | 259 virtual void OnViewManagerDisconnected( |
| 260 ViewManager* view_manager) OVERRIDE { | 260 ViewManager* view_manager) override { |
| 261 DCHECK_EQ(view_manager_, view_manager); | 261 DCHECK_EQ(view_manager_, view_manager); |
| 262 view_manager_ = NULL; | 262 view_manager_ = NULL; |
| 263 base::MessageLoop::current()->Quit(); | 263 base::MessageLoop::current()->Quit(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Overridden from ControlPanel::Delegate: | 266 // Overridden from ControlPanel::Delegate: |
| 267 virtual void ButtonPressed(ControlPanel::ControlType type) OVERRIDE { | 267 virtual void ButtonPressed(ControlPanel::ControlType type) override { |
| 268 switch (type) { | 268 switch (type) { |
| 269 case ControlPanel::CONTROL_ZOOM_IN: | 269 case ControlPanel::CONTROL_ZOOM_IN: |
| 270 zoomable_media_->ZoomIn(); | 270 zoomable_media_->ZoomIn(); |
| 271 break; | 271 break; |
| 272 case ControlPanel::CONTROL_ACTUAL_SIZE: | 272 case ControlPanel::CONTROL_ACTUAL_SIZE: |
| 273 zoomable_media_->ZoomToActualSize(); | 273 zoomable_media_->ZoomToActualSize(); |
| 274 break; | 274 break; |
| 275 case ControlPanel::CONTROL_ZOOM_OUT: | 275 case ControlPanel::CONTROL_ZOOM_OUT: |
| 276 zoomable_media_->ZoomOut(); | 276 zoomable_media_->ZoomOut(); |
| 277 break; | 277 break; |
| 278 default: | 278 default: |
| 279 NOTIMPLEMENTED(); | 279 NOTIMPLEMENTED(); |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 | 282 |
| 283 // ViewObserver: | 283 // ViewObserver: |
| 284 virtual void OnViewBoundsChanged(View* view, | 284 virtual void OnViewBoundsChanged(View* view, |
| 285 const gfx::Rect& old_bounds, | 285 const gfx::Rect& old_bounds, |
| 286 const gfx::Rect& new_bounds) OVERRIDE { | 286 const gfx::Rect& new_bounds) override { |
| 287 LayoutViews(); | 287 LayoutViews(); |
| 288 } | 288 } |
| 289 virtual void OnViewDestroyed(View* view) OVERRIDE { | 289 virtual void OnViewDestroyed(View* view) override { |
| 290 DCHECK_EQ(view, root_view_); | 290 DCHECK_EQ(view, root_view_); |
| 291 view->RemoveObserver(this); | 291 view->RemoveObserver(this); |
| 292 root_view_ = NULL; | 292 root_view_ = NULL; |
| 293 } | 293 } |
| 294 | 294 |
| 295 std::string GetHandlerForContentType(const std::string& content_type) { | 295 std::string GetHandlerForContentType(const std::string& content_type) { |
| 296 HandlerMap::const_iterator it = handler_map_.find(content_type); | 296 HandlerMap::const_iterator it = handler_map_.find(content_type); |
| 297 return it != handler_map_.end() ? it->second : std::string(); | 297 return it != handler_map_.end() ? it->second : std::string(); |
| 298 } | 298 } |
| 299 | 299 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 312 DISALLOW_COPY_AND_ASSIGN(MediaViewer); | 312 DISALLOW_COPY_AND_ASSIGN(MediaViewer); |
| 313 }; | 313 }; |
| 314 | 314 |
| 315 } // namespace examples | 315 } // namespace examples |
| 316 } // namespace mojo | 316 } // namespace mojo |
| 317 | 317 |
| 318 MojoResult MojoMain(MojoHandle shell_handle) { | 318 MojoResult MojoMain(MojoHandle shell_handle) { |
| 319 mojo::ApplicationRunnerChromium runner(new mojo::examples::MediaViewer); | 319 mojo::ApplicationRunnerChromium runner(new mojo::examples::MediaViewer); |
| 320 return runner.Run(shell_handle); | 320 return runner.Run(shell_handle); |
| 321 } | 321 } |
| OLD | NEW |