| 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/dom_ui/menu_ui.h" | 5 #include "chrome/browser/chromeos/dom_ui/menu_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/string_piece.h" | 15 #include "base/string_piece.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "base/weak_ptr.h" | 18 #include "base/weak_ptr.h" |
| 19 #include "chrome/browser/browser_thread.h" | 19 #include "chrome/browser/browser_thread.h" |
| 20 #include "chrome/browser/chromeos/views/domui_menu_widget.h" | |
| 21 #include "chrome/browser/chromeos/views/native_menu_domui.h" | 20 #include "chrome/browser/chromeos/views/native_menu_domui.h" |
| 21 #include "chrome/browser/chromeos/views/webui_menu_widget.h" |
| 22 #include "chrome/browser/dom_ui/web_ui_util.h" | 22 #include "chrome/browser/dom_ui/web_ui_util.h" |
| 23 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
| 24 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 24 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
| 25 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
| 26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/jstemplate_builder.h" | 27 #include "chrome/common/jstemplate_builder.h" |
| 28 #include "gfx/canvas_skia.h" | 28 #include "gfx/canvas_skia.h" |
| 29 #include "gfx/favicon_size.h" | 29 #include "gfx/favicon_size.h" |
| 30 #include "gfx/font.h" | 30 #include "gfx/font.h" |
| 31 #include "grit/app_resources.h" | 31 #include "grit/app_resources.h" |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 std::string index_str; | 396 std::string index_str; |
| 397 bool success = values->GetString(0, &index_str); | 397 bool success = values->GetString(0, &index_str); |
| 398 DCHECK(success); | 398 DCHECK(success); |
| 399 std::string activation; | 399 std::string activation; |
| 400 success = values->GetString(1, &activation); | 400 success = values->GetString(1, &activation); |
| 401 DCHECK(success); | 401 DCHECK(success); |
| 402 | 402 |
| 403 int index; | 403 int index; |
| 404 success = base::StringToInt(index_str, &index); | 404 success = base::StringToInt(index_str, &index); |
| 405 DCHECK(success); | 405 DCHECK(success); |
| 406 chromeos::DOMUIMenuControl* control = GetMenuControl(); | 406 chromeos::WebUIMenuControl* control = GetMenuControl(); |
| 407 if (control) { | 407 if (control) { |
| 408 ui::MenuModel* model = GetMenuModel(); | 408 ui::MenuModel* model = GetMenuModel(); |
| 409 DCHECK(model); | 409 DCHECK(model); |
| 410 DCHECK_GE(index, 0); | 410 DCHECK_GE(index, 0); |
| 411 DCHECK(activation == "close_and_activate" || | 411 DCHECK(activation == "close_and_activate" || |
| 412 activation == "activate_no_close") << activation; | 412 activation == "activate_no_close") << activation; |
| 413 if (model->IsEnabledAt(index)) { | 413 if (model->IsEnabledAt(index)) { |
| 414 control->Activate(model, | 414 control->Activate(model, |
| 415 index, | 415 index, |
| 416 activation == "close_and_activate" ? | 416 activation == "close_and_activate" ? |
| 417 chromeos::DOMUIMenuControl::CLOSE_AND_ACTIVATE : | 417 chromeos::WebUIMenuControl::CLOSE_AND_ACTIVATE : |
| 418 chromeos::DOMUIMenuControl::ACTIVATE_NO_CLOSE); | 418 chromeos::WebUIMenuControl::ACTIVATE_NO_CLOSE); |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 | 422 |
| 423 void MenuHandler::HandleOpenSubmenu(const ListValue* values) { | 423 void MenuHandler::HandleOpenSubmenu(const ListValue* values) { |
| 424 CHECK_EQ(2U, values->GetSize()); | 424 CHECK_EQ(2U, values->GetSize()); |
| 425 std::string index_str; | 425 std::string index_str; |
| 426 bool success = values->GetString(0, &index_str); | 426 bool success = values->GetString(0, &index_str); |
| 427 DCHECK(success); | 427 DCHECK(success); |
| 428 std::string y_str; | 428 std::string y_str; |
| 429 success = values->GetString(1, &y_str); | 429 success = values->GetString(1, &y_str); |
| 430 DCHECK(success); | 430 DCHECK(success); |
| 431 int index; | 431 int index; |
| 432 success = base::StringToInt(index_str, &index); | 432 success = base::StringToInt(index_str, &index); |
| 433 DCHECK(success); | 433 DCHECK(success); |
| 434 int y; | 434 int y; |
| 435 success = base::StringToInt(y_str, &y); | 435 success = base::StringToInt(y_str, &y); |
| 436 DCHECK(success); | 436 DCHECK(success); |
| 437 chromeos::DOMUIMenuControl* control = GetMenuControl(); | 437 chromeos::WebUIMenuControl* control = GetMenuControl(); |
| 438 if (control) | 438 if (control) |
| 439 control->OpenSubmenu(index, y); | 439 control->OpenSubmenu(index, y); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void MenuHandler::HandleCloseSubmenu(const ListValue* values) { | 442 void MenuHandler::HandleCloseSubmenu(const ListValue* values) { |
| 443 chromeos::DOMUIMenuControl* control = GetMenuControl(); | 443 chromeos::WebUIMenuControl* control = GetMenuControl(); |
| 444 if (control) | 444 if (control) |
| 445 control->CloseSubmenu(); | 445 control->CloseSubmenu(); |
| 446 } | 446 } |
| 447 | 447 |
| 448 void MenuHandler::HandleMoveInputToSubmenu(const ListValue* values) { | 448 void MenuHandler::HandleMoveInputToSubmenu(const ListValue* values) { |
| 449 chromeos::DOMUIMenuControl* control = GetMenuControl(); | 449 chromeos::WebUIMenuControl* control = GetMenuControl(); |
| 450 if (control) | 450 if (control) |
| 451 control->MoveInputToSubmenu(); | 451 control->MoveInputToSubmenu(); |
| 452 } | 452 } |
| 453 | 453 |
| 454 void MenuHandler::HandleMoveInputToParent(const ListValue* values) { | 454 void MenuHandler::HandleMoveInputToParent(const ListValue* values) { |
| 455 chromeos::DOMUIMenuControl* control = GetMenuControl(); | 455 chromeos::WebUIMenuControl* control = GetMenuControl(); |
| 456 if (control) | 456 if (control) |
| 457 control->MoveInputToParent(); | 457 control->MoveInputToParent(); |
| 458 } | 458 } |
| 459 | 459 |
| 460 void MenuHandler::HandleCloseAll(const ListValue* values) { | 460 void MenuHandler::HandleCloseAll(const ListValue* values) { |
| 461 chromeos::DOMUIMenuControl* control = GetMenuControl(); | 461 chromeos::WebUIMenuControl* control = GetMenuControl(); |
| 462 if (control) | 462 if (control) |
| 463 control->CloseAll(); | 463 control->CloseAll(); |
| 464 } | 464 } |
| 465 | 465 |
| 466 void MenuHandler::HandleModelUpdated(const ListValue* values) { | 466 void MenuHandler::HandleModelUpdated(const ListValue* values) { |
| 467 ui::MenuModel* model = GetMenuModel(); | 467 ui::MenuModel* model = GetMenuModel(); |
| 468 if (model) | 468 if (model) |
| 469 static_cast<chromeos::MenuUI*>(dom_ui_)->ModelUpdated(model); | 469 static_cast<chromeos::MenuUI*>(dom_ui_)->ModelUpdated(model); |
| 470 } | 470 } |
| 471 | 471 |
| 472 void MenuHandler::HandleLog(const ListValue* values) { | 472 void MenuHandler::HandleLog(const ListValue* values) { |
| 473 CHECK_EQ(1U, values->GetSize()); | 473 CHECK_EQ(1U, values->GetSize()); |
| 474 std::string msg; | 474 std::string msg; |
| 475 bool success = values->GetString(0, &msg); | 475 bool success = values->GetString(0, &msg); |
| 476 DCHECK(success); | 476 DCHECK(success); |
| 477 DVLOG(1) << msg; | 477 DVLOG(1) << msg; |
| 478 } | 478 } |
| 479 | 479 |
| 480 void MenuHandler::UpdatePreferredSize(const gfx::Size& new_size) { | 480 void MenuHandler::UpdatePreferredSize(const gfx::Size& new_size) { |
| 481 if (!loaded_) | 481 if (!loaded_) |
| 482 return; | 482 return; |
| 483 chromeos::DOMUIMenuControl* control = GetMenuControl(); | 483 chromeos::WebUIMenuControl* control = GetMenuControl(); |
| 484 if (control) | 484 if (control) |
| 485 control->SetSize(new_size); | 485 control->SetSize(new_size); |
| 486 } | 486 } |
| 487 | 487 |
| 488 void MenuHandler::LoadingStateChanged(TabContents* contents) { | 488 void MenuHandler::LoadingStateChanged(TabContents* contents) { |
| 489 chromeos::DOMUIMenuControl* control = GetMenuControl(); | 489 chromeos::WebUIMenuControl* control = GetMenuControl(); |
| 490 if (control && !contents->is_loading()) { | 490 if (control && !contents->is_loading()) { |
| 491 loaded_ = true; | 491 loaded_ = true; |
| 492 control->OnLoad(); | 492 control->OnLoad(); |
| 493 HandleModelUpdated(NULL); | 493 HandleModelUpdated(NULL); |
| 494 } | 494 } |
| 495 } | 495 } |
| 496 | 496 |
| 497 } // namespace | 497 } // namespace |
| 498 | 498 |
| 499 namespace chromeos { | 499 namespace chromeos { |
| 500 | 500 |
| 501 //////////////////////////////////////////////////////////////////////////////// | 501 //////////////////////////////////////////////////////////////////////////////// |
| 502 // | 502 // |
| 503 // MenuHandlerBase | 503 // MenuHandlerBase |
| 504 // | 504 // |
| 505 //////////////////////////////////////////////////////////////////////////////// | 505 //////////////////////////////////////////////////////////////////////////////// |
| 506 | 506 |
| 507 chromeos::DOMUIMenuControl* MenuHandlerBase::GetMenuControl() { | 507 chromeos::WebUIMenuControl* MenuHandlerBase::GetMenuControl() { |
| 508 DOMUIMenuWidget* widget = | 508 WebUIMenuWidget* widget = |
| 509 chromeos::DOMUIMenuWidget::FindDOMUIMenuWidget( | 509 chromeos::WebUIMenuWidget::FindWebUIMenuWidget( |
| 510 dom_ui_->tab_contents()->GetNativeView()); | 510 dom_ui_->tab_contents()->GetNativeView()); |
| 511 if (widget) | 511 if (widget) |
| 512 return widget->domui_menu(); // NativeMenuDOMUI implements DOMUIMenuControl | 512 return widget->domui_menu(); // NativeMenuDOMUI implements WebUIMenuControl |
| 513 else | 513 else |
| 514 return NULL; | 514 return NULL; |
| 515 } | 515 } |
| 516 | 516 |
| 517 ui::MenuModel* MenuHandlerBase::GetMenuModel() { | 517 ui::MenuModel* MenuHandlerBase::GetMenuModel() { |
| 518 DOMUIMenuControl* control = GetMenuControl(); | 518 WebUIMenuControl* control = GetMenuControl(); |
| 519 if (control) | 519 if (control) |
| 520 return control->GetMenuModel(); | 520 return control->GetMenuModel(); |
| 521 else | 521 else |
| 522 return NULL; | 522 return NULL; |
| 523 } | 523 } |
| 524 | 524 |
| 525 //////////////////////////////////////////////////////////////////////////////// | 525 //////////////////////////////////////////////////////////////////////////////// |
| 526 // | 526 // |
| 527 // MenuUI | 527 // MenuUI |
| 528 // | 528 // |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 item = CreateMenuItem(model, index, "check", | 586 item = CreateMenuItem(model, index, "check", |
| 587 &max_icon_width, &has_accelerator); | 587 &max_icon_width, &has_accelerator); |
| 588 break; | 588 break; |
| 589 default: | 589 default: |
| 590 // TODO(oshima): We don't support BUTTOM_ITEM for now. | 590 // TODO(oshima): We don't support BUTTOM_ITEM for now. |
| 591 NOTREACHED(); | 591 NOTREACHED(); |
| 592 continue; | 592 continue; |
| 593 } | 593 } |
| 594 items->Set(index, item); | 594 items->Set(index, item); |
| 595 } | 595 } |
| 596 DOMUIMenuWidget* widget = | 596 WebUIMenuWidget* widget = |
| 597 chromeos::DOMUIMenuWidget::FindDOMUIMenuWidget( | 597 chromeos::WebUIMenuWidget::FindWebUIMenuWidget( |
| 598 tab_contents()->GetNativeView()); | 598 tab_contents()->GetNativeView()); |
| 599 DCHECK(widget); | 599 DCHECK(widget); |
| 600 json_model.SetInteger("maxIconWidth", max_icon_width); | 600 json_model.SetInteger("maxIconWidth", max_icon_width); |
| 601 json_model.SetBoolean("isRoot", widget->is_root()); | 601 json_model.SetBoolean("isRoot", widget->is_root()); |
| 602 json_model.SetBoolean("hasAccelerator", has_accelerator); | 602 json_model.SetBoolean("hasAccelerator", has_accelerator); |
| 603 CallJavascriptFunction(L"updateModel", json_model); | 603 CallJavascriptFunction(L"updateModel", json_model); |
| 604 } | 604 } |
| 605 | 605 |
| 606 DictionaryValue* MenuUI::CreateMenuItem(const ui::MenuModel* model, | 606 DictionaryValue* MenuUI::CreateMenuItem(const ui::MenuModel* model, |
| 607 int index, | 607 int index, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 655 |
| 656 ChromeURLDataManager::DataSource* MenuUI::CreateDataSource() { | 656 ChromeURLDataManager::DataSource* MenuUI::CreateDataSource() { |
| 657 return CreateMenuUIHTMLSource(NULL, | 657 return CreateMenuUIHTMLSource(NULL, |
| 658 chrome::kChromeUIMenu, | 658 chrome::kChromeUIMenu, |
| 659 "Menu" /* class name */, | 659 "Menu" /* class name */, |
| 660 kNoExtraResource, | 660 kNoExtraResource, |
| 661 kNoExtraResource); | 661 kNoExtraResource); |
| 662 } | 662 } |
| 663 | 663 |
| 664 } // namespace chromeos | 664 } // namespace chromeos |
| OLD | NEW |