| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/views/webui_menu_widget.h" | 5 #include "chrome/browser/chromeos/views/webui_menu_widget.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 | 8 | 
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" | 
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 75   DISALLOW_COPY_AND_ASSIGN(RoundedBorder); | 75   DISALLOW_COPY_AND_ASSIGN(RoundedBorder); | 
| 76 }; | 76 }; | 
| 77 | 77 | 
| 78 class InsetsLayout : public views::LayoutManager { | 78 class InsetsLayout : public views::LayoutManager { | 
| 79  public: | 79  public: | 
| 80   InsetsLayout() : views::LayoutManager() {} | 80   InsetsLayout() : views::LayoutManager() {} | 
| 81 | 81 | 
| 82  private: | 82  private: | 
| 83   // views::LayoutManager implementatios. | 83   // views::LayoutManager implementatios. | 
| 84   virtual void Layout(views::View* host) { | 84   virtual void Layout(views::View* host) { | 
| 85     if (host->GetChildViewCount() == 0) | 85     if (!host->has_children()) | 
| 86       return; | 86       return; | 
| 87     gfx::Insets insets = host->GetInsets(); | 87     gfx::Insets insets = host->GetInsets(); | 
| 88     views::View* view = host->GetChildViewAt(0); | 88     views::View* view = host->GetChildViewAt(0); | 
| 89 | 89 | 
| 90     view->SetBounds(insets.left(), insets.top(), | 90     view->SetBounds(insets.left(), insets.top(), | 
| 91                     host->width() - insets.width(), | 91                     host->width() - insets.width(), | 
| 92                     host->height() - insets.height()); | 92                     host->height() - insets.height()); | 
| 93   } | 93   } | 
| 94 | 94 | 
| 95   virtual gfx::Size GetPreferredSize(views::View* host) { | 95   virtual gfx::Size GetPreferredSize(views::View* host) { | 
| 96     DCHECK(host->GetChildViewCount() == 1); | 96     DCHECK(host->child_count() == 1); | 
| 97     gfx::Insets insets = host->GetInsets(); | 97     gfx::Insets insets = host->GetInsets(); | 
| 98     gfx::Size size = host->GetChildViewAt(0)->GetPreferredSize(); | 98     gfx::Size size = host->GetChildViewAt(0)->GetPreferredSize(); | 
| 99     return gfx::Size(size.width() + insets.width(), | 99     return gfx::Size(size.width() + insets.width(), | 
| 100                      size.height() + insets.height()); | 100                      size.height() + insets.height()); | 
| 101   } | 101   } | 
| 102 | 102 | 
| 103   DISALLOW_COPY_AND_ASSIGN(InsetsLayout); | 103   DISALLOW_COPY_AND_ASSIGN(InsetsLayout); | 
| 104 }; | 104 }; | 
| 105 | 105 | 
| 106 // A gtk widget key used to test if a given WidgetGtk instance is | 106 // A gtk widget key used to test if a given WidgetGtk instance is | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 150 | 150 | 
| 151 void WebUIMenuWidget::Hide() { | 151 void WebUIMenuWidget::Hide() { | 
| 152   ReleaseGrab(); | 152   ReleaseGrab(); | 
| 153   WidgetGtk::Hide(); | 153   WidgetGtk::Hide(); | 
| 154   // Clears the content. | 154   // Clears the content. | 
| 155   ExecuteJavascript(L"updateModel({'items':[]})"); | 155   ExecuteJavascript(L"updateModel({'items':[]})"); | 
| 156 } | 156 } | 
| 157 | 157 | 
| 158 void WebUIMenuWidget::Close() { | 158 void WebUIMenuWidget::Close() { | 
| 159   if (dom_view_ != NULL) { | 159   if (dom_view_ != NULL) { | 
| 160     dom_view_->GetParent()->RemoveChildView(dom_view_); | 160     dom_view_->parent()->RemoveChildView(dom_view_); | 
| 161     delete dom_view_; | 161     delete dom_view_; | 
| 162     dom_view_ = NULL; | 162     dom_view_ = NULL; | 
| 163   } | 163   } | 
| 164 | 164 | 
| 165   // Detach the webui_menu_ which is being deleted. | 165   // Detach the webui_menu_ which is being deleted. | 
| 166   webui_menu_ = NULL; | 166   webui_menu_ = NULL; | 
| 167   views::WidgetGtk::Close(); | 167   views::WidgetGtk::Close(); | 
| 168 } | 168 } | 
| 169 | 169 | 
| 170 void WebUIMenuWidget::ReleaseGrab() { | 170 void WebUIMenuWidget::ReleaseGrab() { | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 267     dom_view_->Init(webui_menu_->GetProfile(), NULL); | 267     dom_view_->Init(webui_menu_->GetProfile(), NULL); | 
| 268     // TODO(oshima): remove extra view to draw rounded corner. | 268     // TODO(oshima): remove extra view to draw rounded corner. | 
| 269     views::View* container = new views::View(); | 269     views::View* container = new views::View(); | 
| 270     container->AddChildView(dom_view_); | 270     container->AddChildView(dom_view_); | 
| 271     container->set_border(new RoundedBorder(locator)); | 271     container->set_border(new RoundedBorder(locator)); | 
| 272     container->SetLayoutManager(new InsetsLayout()); | 272     container->SetLayoutManager(new InsetsLayout()); | 
| 273     SetContentsView(container); | 273     SetContentsView(container); | 
| 274     dom_view_->LoadURL(webui_menu_->menu_url()); | 274     dom_view_->LoadURL(webui_menu_->menu_url()); | 
| 275   } else { | 275   } else { | 
| 276     webui_menu_->UpdateStates(); | 276     webui_menu_->UpdateStates(); | 
| 277     dom_view_->GetParent()->set_border(new RoundedBorder(locator)); | 277     dom_view_->parent()->set_border(new RoundedBorder(locator)); | 
| 278     menu_locator_->Move(this); | 278     menu_locator_->Move(this); | 
| 279   } | 279   } | 
| 280   Show(); | 280   Show(); | 
| 281 | 281 | 
| 282   // The pointer grab is captured only on the top level menu, | 282   // The pointer grab is captured only on the top level menu, | 
| 283   // all mouse event events are delivered to submenu using gtk_add_grab. | 283   // all mouse event events are delivered to submenu using gtk_add_grab. | 
| 284   if (is_root_) { | 284   if (is_root_) { | 
| 285     CaptureGrab(); | 285     CaptureGrab(); | 
| 286   } | 286   } | 
| 287 } | 287 } | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 331   EnableInput(false /* no selection */); | 331   EnableInput(false /* no selection */); | 
| 332 } | 332 } | 
| 333 | 333 | 
| 334 void WebUIMenuWidget::ClearGrabWidget() { | 334 void WebUIMenuWidget::ClearGrabWidget() { | 
| 335   GtkWidget* grab_widget; | 335   GtkWidget* grab_widget; | 
| 336   while ((grab_widget = gtk_grab_get_current())) | 336   while ((grab_widget = gtk_grab_get_current())) | 
| 337     gtk_grab_remove(grab_widget); | 337     gtk_grab_remove(grab_widget); | 
| 338 } | 338 } | 
| 339 | 339 | 
| 340 }   // namespace chromeos | 340 }   // namespace chromeos | 
| OLD | NEW | 
|---|