| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/menu/submenu_view.h" | 5 #include "views/controls/menu/submenu_view.h" |
| 6 | 6 |
| 7 #include "gfx/canvas.h" | 7 #include "gfx/canvas.h" |
| 8 #include "views/controls/menu/menu_controller.h" | 8 #include "views/controls/menu/menu_controller.h" |
| 9 #include "views/controls/menu/menu_host.h" |
| 9 #include "views/controls/menu/menu_scroll_view_container.h" | 10 #include "views/controls/menu/menu_scroll_view_container.h" |
| 10 #include "views/widget/root_view.h" | 11 #include "views/widget/root_view.h" |
| 11 | 12 |
| 12 #if defined(OS_WIN) | |
| 13 #include "views/controls/menu/menu_host_win.h" | |
| 14 #elif defined(OS_LINUX) | |
| 15 #include "views/controls/menu/menu_host_gtk.h" | |
| 16 #endif | |
| 17 | |
| 18 // Height of the drop indicator. This should be an even number. | 13 // Height of the drop indicator. This should be an even number. |
| 19 static const int kDropIndicatorHeight = 2; | 14 static const int kDropIndicatorHeight = 2; |
| 20 | 15 |
| 21 // Color of the drop indicator. | 16 // Color of the drop indicator. |
| 22 static const SkColor kDropIndicatorColor = SK_ColorBLACK; | 17 static const SkColor kDropIndicatorColor = SK_ColorBLACK; |
| 23 | 18 |
| 24 namespace views { | 19 namespace views { |
| 25 | 20 |
| 26 // static | 21 // static |
| 27 const int SubmenuView::kSubmenuBorderSize = 3; | 22 const int SubmenuView::kSubmenuBorderSize = 3; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 196 } |
| 202 ScrollRectToVisible(gfx::Rect(gfx::Point(0, scroll_target), | 197 ScrollRectToVisible(gfx::Rect(gfx::Point(0, scroll_target), |
| 203 vis_bounds.size())); | 198 vis_bounds.size())); |
| 204 vis_bounds = GetVisibleBounds(); | 199 vis_bounds = GetVisibleBounds(); |
| 205 } | 200 } |
| 206 | 201 |
| 207 return true; | 202 return true; |
| 208 } | 203 } |
| 209 | 204 |
| 210 bool SubmenuView::IsShowing() { | 205 bool SubmenuView::IsShowing() { |
| 211 return host_ && host_->IsVisible(); | 206 return host_ && host_->IsMenuHostVisible(); |
| 212 } | 207 } |
| 213 | 208 |
| 214 void SubmenuView::ShowAt(gfx::NativeWindow parent, | 209 void SubmenuView::ShowAt(gfx::NativeWindow parent, |
| 215 const gfx::Rect& bounds, | 210 const gfx::Rect& bounds, |
| 216 bool do_capture) { | 211 bool do_capture) { |
| 217 if (host_) { | 212 if (host_) { |
| 218 host_->Show(); | 213 host_->ShowMenuHost(do_capture); |
| 219 if (do_capture) | |
| 220 host_->DoCapture(); | |
| 221 return; | 214 return; |
| 222 } | 215 } |
| 223 | 216 |
| 224 host_ = new MenuHost(this); | 217 host_ = MenuHost::Create(this); |
| 225 // Force construction of the scroll view container. | 218 // Force construction of the scroll view container. |
| 226 GetScrollViewContainer(); | 219 GetScrollViewContainer(); |
| 227 // Make sure the first row is visible. | 220 // Make sure the first row is visible. |
| 228 ScrollRectToVisible(gfx::Rect(gfx::Point(), gfx::Size(1, 1))); | 221 ScrollRectToVisible(gfx::Rect(gfx::Point(), gfx::Size(1, 1))); |
| 229 host_->Init(parent, bounds, scroll_view_container_, do_capture); | 222 host_->Init(parent, bounds, scroll_view_container_, do_capture); |
| 230 } | 223 } |
| 231 | 224 |
| 232 void SubmenuView::Reposition(const gfx::Rect& bounds) { | 225 void SubmenuView::Reposition(const gfx::Rect& bounds) { |
| 233 host_->SetBounds(bounds); | 226 if (host_) |
| 227 host_->SetMenuHostBounds(bounds); |
| 234 } | 228 } |
| 235 | 229 |
| 236 void SubmenuView::Close() { | 230 void SubmenuView::Close() { |
| 237 if (host_) { | 231 if (host_) { |
| 238 host_->Close(); | 232 host_->DestroyMenuHost(); |
| 239 host_ = NULL; | 233 host_ = NULL; |
| 240 } | 234 } |
| 241 } | 235 } |
| 242 | 236 |
| 243 void SubmenuView::Hide() { | 237 void SubmenuView::Hide() { |
| 244 if (host_) | 238 if (host_) |
| 245 host_->HideWindow(); | 239 host_->HideMenuHost(); |
| 246 } | 240 } |
| 247 | 241 |
| 248 void SubmenuView::ReleaseCapture() { | 242 void SubmenuView::ReleaseCapture() { |
| 249 host_->ReleaseCapture(); | 243 if (host_) |
| 244 host_->ReleaseMenuHostCapture(); |
| 250 } | 245 } |
| 251 | 246 |
| 252 bool SubmenuView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { | 247 bool SubmenuView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) { |
| 253 return views::FocusManager::IsTabTraversalKeyEvent(e); | 248 return views::FocusManager::IsTabTraversalKeyEvent(e); |
| 254 } | 249 } |
| 255 | 250 |
| 256 void SubmenuView::SetDropMenuItem(MenuItemView* item, | 251 void SubmenuView::SetDropMenuItem(MenuItemView* item, |
| 257 MenuDelegate::DropPosition position) { | 252 MenuDelegate::DropPosition position) { |
| 258 if (drop_item_ == item && drop_position_ == position) | 253 if (drop_item_ == item && drop_position_ == position) |
| 259 return; | 254 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 275 MenuScrollViewContainer* SubmenuView::GetScrollViewContainer() { | 270 MenuScrollViewContainer* SubmenuView::GetScrollViewContainer() { |
| 276 if (!scroll_view_container_) { | 271 if (!scroll_view_container_) { |
| 277 scroll_view_container_ = new MenuScrollViewContainer(this); | 272 scroll_view_container_ = new MenuScrollViewContainer(this); |
| 278 // Otherwise MenuHost would delete us. | 273 // Otherwise MenuHost would delete us. |
| 279 scroll_view_container_->set_parent_owned(false); | 274 scroll_view_container_->set_parent_owned(false); |
| 280 } | 275 } |
| 281 return scroll_view_container_; | 276 return scroll_view_container_; |
| 282 } | 277 } |
| 283 | 278 |
| 284 gfx::NativeWindow SubmenuView::native_window() const { | 279 gfx::NativeWindow SubmenuView::native_window() const { |
| 285 return host_ ? host_->GetNativeWindow() : NULL; | 280 return host_ ? host_->GetMenuHostWindow() : NULL; |
| 281 } |
| 282 |
| 283 void SubmenuView::MenuHostDestroyed() { |
| 284 host_ = NULL; |
| 285 GetMenuItem()->GetMenuController()->Cancel(MenuController::EXIT_DESTROYED); |
| 286 } | 286 } |
| 287 | 287 |
| 288 void SubmenuView::PaintDropIndicator(gfx::Canvas* canvas, | 288 void SubmenuView::PaintDropIndicator(gfx::Canvas* canvas, |
| 289 MenuItemView* item, | 289 MenuItemView* item, |
| 290 MenuDelegate::DropPosition position) { | 290 MenuDelegate::DropPosition position) { |
| 291 if (position == MenuDelegate::DROP_NONE) | 291 if (position == MenuDelegate::DROP_NONE) |
| 292 return; | 292 return; |
| 293 | 293 |
| 294 gfx::Rect bounds = CalculateDropIndicatorBounds(item, position); | 294 gfx::Rect bounds = CalculateDropIndicatorBounds(item, position); |
| 295 canvas->FillRectInt(kDropIndicatorColor, bounds.x(), bounds.y(), | 295 canvas->FillRectInt(kDropIndicatorColor, bounds.x(), bounds.y(), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 325 item_bounds.set_height(kDropIndicatorHeight); | 325 item_bounds.set_height(kDropIndicatorHeight); |
| 326 return item_bounds; | 326 return item_bounds; |
| 327 | 327 |
| 328 default: | 328 default: |
| 329 // Don't render anything for on. | 329 // Don't render anything for on. |
| 330 return gfx::Rect(); | 330 return gfx::Rect(); |
| 331 } | 331 } |
| 332 } | 332 } |
| 333 | 333 |
| 334 } // namespace views | 334 } // namespace views |
| OLD | NEW |