macOS: cefclient: Create Tests menu with Interface Builder
This commit is contained in:
parent
94f604975d
commit
d6531b9fe6
|
@ -17,11 +17,23 @@
|
|||
|
||||
namespace {
|
||||
|
||||
void AddMenuItem(NSMenu *menu, NSString* label, int idval) {
|
||||
NSMenuItem* item = [menu addItemWithTitle:label
|
||||
action:@selector(menuItemSelected:)
|
||||
keyEquivalent:@""];
|
||||
[item setTag:idval];
|
||||
// Returns the top menu bar with the specified |tag|.
|
||||
NSMenuItem* GetMenuBarMenuWithTag(NSInteger tag) {
|
||||
NSMenu* main_menu = NSApp.mainMenu;
|
||||
NSInteger found_index = [main_menu indexOfItemWithTag:tag];
|
||||
if (found_index >= 0)
|
||||
return [main_menu itemAtIndex:found_index];
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Returns the item in |menu| that has the specified |action_selector|.
|
||||
NSMenuItem* GetMenuItemWithAction(NSMenu* menu, SEL action_selector) {
|
||||
for (NSInteger i = 0; i < menu.numberOfItems; ++i) {
|
||||
NSMenuItem* item = [menu itemAtIndex:i];
|
||||
if (item.action == action_selector)
|
||||
return item;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -36,7 +48,23 @@ void AddMenuItem(NSMenu *menu, NSString* label, int idval) {
|
|||
- (id)initWithControls:(bool)with_controls andOsr:(bool)with_osr;
|
||||
- (void)createApplication:(id)object;
|
||||
- (void)tryToTerminateApplication:(NSApplication*)app;
|
||||
- (IBAction)menuItemSelected:(id)sender;
|
||||
- (void)testsItemSelected:(int)command_id;
|
||||
- (IBAction)menuTestsGetText:(id)sender;
|
||||
- (IBAction)menuTestsGetSource:(id)sender;
|
||||
- (IBAction)menuTestsWindowNew:(id)sender;
|
||||
- (IBAction)menuTestsWindowPopup:(id)sender;
|
||||
- (IBAction)menuTestsRequest:(id)sender;
|
||||
- (IBAction)menuTestsPluginInfo:(id)sender;
|
||||
- (IBAction)menuTestsZoomIn:(id)sender;
|
||||
- (IBAction)menuTestsZoomOut:(id)sender;
|
||||
- (IBAction)menuTestsZoomReset:(id)sender;
|
||||
- (IBAction)menuTestsSetFPS:(id)sender;
|
||||
- (IBAction)menuTestsSetScaleFactor:(id)sender;
|
||||
- (IBAction)menuTestsTracingBegin:(id)sender;
|
||||
- (IBAction)menuTestsTracingEnd:(id)sender;
|
||||
- (IBAction)menuTestsPrint:(id)sender;
|
||||
- (IBAction)menuTestsPrintToPdf:(id)sender;
|
||||
- (IBAction)menuTestsOtherTests:(id)sender;
|
||||
@end
|
||||
|
||||
// Provide the CefAppProtocol implementation required by CEF.
|
||||
|
@ -119,39 +147,61 @@ void AddMenuItem(NSMenu *menu, NSString* label, int idval) {
|
|||
// Create the application on the UI thread.
|
||||
- (void)createApplication:(id)object {
|
||||
NSApplication* application = [NSApplication sharedApplication];
|
||||
|
||||
// The top menu is configured using Interface Builder (IB). To modify the menu
|
||||
// start by loading MainMenu.xib in IB.
|
||||
//
|
||||
// To associate MainMenu.xib with ClientAppDelegate:
|
||||
// 1. Select "File's Owner" from the "Placeholders" section in the left side
|
||||
// pane.
|
||||
// 2. Load the "Identity inspector" tab in the top-right side pane.
|
||||
// 3. In the "Custom Class" section set the "Class" value to
|
||||
// "ClientAppDelegate".
|
||||
// 4. Pass an instance of ClientAppDelegate as the |owner| parameter to
|
||||
// loadNibNamed:.
|
||||
//
|
||||
// To create a new top menu:
|
||||
// 1. Load the "Object library" tab in the bottom-right side pane.
|
||||
// 2. Drag a "Submenu Menu Item" widget from the Object library to the desired
|
||||
// location in the menu bar shown in the center pane.
|
||||
// 3. Select the newly created top menu by left clicking on it.
|
||||
// 4. Load the "Attributes inspector" tab in the top-right side pane.
|
||||
// 5. Under the "Menu Item" section set the "Tag" value to a unique integer.
|
||||
// This is necessary for the GetMenuBarMenuWithTag function to work
|
||||
// properly.
|
||||
//
|
||||
// To create a new menu item in a top menu:
|
||||
// 1. Add a new receiver method in ClientAppDelegate (e.g. menuTestsDoStuff:).
|
||||
// 2. Load the "Object library" tab in the bottom-right side pane.
|
||||
// 3. Drag a "Menu Item" widget from the Object library to the desired
|
||||
// location in the menu bar shown in the center pane.
|
||||
// 4. Double-click on the new menu item to set the label.
|
||||
// 5. Right click on the new menu item to show the "Get Source" dialog.
|
||||
// 6. In the "Sent Actions" section drag from the circle icon and drop on the
|
||||
// new receiver method in the ClientAppDelegate source code file.
|
||||
//
|
||||
// Load the top menu from MainMenu.xib.
|
||||
[[NSBundle mainBundle] loadNibNamed:@"MainMenu"
|
||||
owner:NSApp
|
||||
owner:self
|
||||
topLevelObjects:nil];
|
||||
|
||||
// Set the delegate for application events.
|
||||
[application setDelegate:self];
|
||||
|
||||
// Add the Tests menu.
|
||||
NSMenu* menubar = [application mainMenu];
|
||||
NSMenuItem *testItem = [[[NSMenuItem alloc] initWithTitle:@"Tests"
|
||||
action:nil
|
||||
keyEquivalent:@""] autorelease];
|
||||
NSMenu *testMenu = [[[NSMenu alloc] initWithTitle:@"Tests"] autorelease];
|
||||
AddMenuItem(testMenu, @"Get Text", ID_TESTS_GETSOURCE);
|
||||
AddMenuItem(testMenu, @"Get Source", ID_TESTS_GETTEXT);
|
||||
AddMenuItem(testMenu, @"New Window", ID_TESTS_WINDOW_NEW);
|
||||
AddMenuItem(testMenu, @"Popup Window", ID_TESTS_WINDOW_POPUP);
|
||||
AddMenuItem(testMenu, @"Request", ID_TESTS_REQUEST);
|
||||
AddMenuItem(testMenu, @"Plugin Info", ID_TESTS_PLUGIN_INFO);
|
||||
AddMenuItem(testMenu, @"Zoom In", ID_TESTS_ZOOM_IN);
|
||||
AddMenuItem(testMenu, @"Zoom Out", ID_TESTS_ZOOM_OUT);
|
||||
AddMenuItem(testMenu, @"Zoom Reset", ID_TESTS_ZOOM_RESET);
|
||||
if (with_osr_) {
|
||||
AddMenuItem(testMenu, @"Set FPS", ID_TESTS_OSR_FPS);
|
||||
AddMenuItem(testMenu, @"Set Scale Factor", ID_TESTS_OSR_DSF);
|
||||
if (!with_osr_) {
|
||||
// Remove the OSR-related menu items when OSR is disabled.
|
||||
NSMenuItem* tests_menu = GetMenuBarMenuWithTag(8);
|
||||
if (tests_menu) {
|
||||
NSMenuItem* set_fps_item = GetMenuItemWithAction(
|
||||
tests_menu.submenu, @selector(menuTestsSetFPS:));
|
||||
if (set_fps_item)
|
||||
[tests_menu.submenu removeItem:set_fps_item];
|
||||
NSMenuItem* set_scale_factor_item = GetMenuItemWithAction(
|
||||
tests_menu.submenu, @selector(menuTestsSetScaleFactor:));
|
||||
if (set_scale_factor_item)
|
||||
[tests_menu.submenu removeItem:set_scale_factor_item];
|
||||
}
|
||||
}
|
||||
AddMenuItem(testMenu, @"Begin Tracing", ID_TESTS_TRACING_BEGIN);
|
||||
AddMenuItem(testMenu, @"End Tracing", ID_TESTS_TRACING_END);
|
||||
AddMenuItem(testMenu, @"Print", ID_TESTS_PRINT);
|
||||
AddMenuItem(testMenu, @"Print to PDF", ID_TESTS_PRINT_TO_PDF);
|
||||
AddMenuItem(testMenu, @"Other Tests", ID_TESTS_OTHER_TESTS);
|
||||
[testItem setSubmenu:testMenu];
|
||||
[menubar addItem:testItem];
|
||||
|
||||
// Create the first window.
|
||||
client::MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
|
||||
|
@ -165,7 +215,11 @@ void AddMenuItem(NSMenu *menu, NSString* label, int idval) {
|
|||
client::MainContext::Get()->GetRootWindowManager()->CloseAllWindows(false);
|
||||
}
|
||||
|
||||
- (IBAction)menuItemSelected:(id)sender {
|
||||
- (void)orderFrontStandardAboutPanel:(id)sender {
|
||||
[[NSApplication sharedApplication] orderFrontStandardAboutPanel:nil];
|
||||
}
|
||||
|
||||
- (void)testsItemSelected:(int)command_id {
|
||||
// Retrieve the active RootWindow.
|
||||
NSWindow* key_window = [[NSApplication sharedApplication] keyWindow];
|
||||
if (!key_window)
|
||||
|
@ -175,10 +229,72 @@ void AddMenuItem(NSMenu *menu, NSString* label, int idval) {
|
|||
client::RootWindow::GetForNSWindow(key_window);
|
||||
|
||||
CefRefPtr<CefBrowser> browser = root_window->GetBrowser();
|
||||
if (browser.get()) {
|
||||
NSMenuItem *item = (NSMenuItem*)sender;
|
||||
client::test_runner::RunTest(browser, [item tag]);
|
||||
}
|
||||
if (browser.get())
|
||||
client::test_runner::RunTest(browser, command_id);
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsGetText:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_GETTEXT];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsGetSource:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_GETSOURCE];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsWindowNew:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_WINDOW_NEW];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsWindowPopup:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_WINDOW_POPUP];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsRequest:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_REQUEST];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsPluginInfo:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_PLUGIN_INFO];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsZoomIn:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_ZOOM_IN];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsZoomOut:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_ZOOM_OUT];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsZoomReset:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_ZOOM_RESET];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsSetFPS:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_OSR_FPS];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsSetScaleFactor:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_OSR_DSF];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsTracingBegin:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_TRACING_BEGIN];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsTracingEnd:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_TRACING_END];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsPrint:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_PRINT];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsPrintToPdf:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_PRINT_TO_PDF];
|
||||
}
|
||||
|
||||
- (IBAction)menuTestsOtherTests:(id)sender {
|
||||
[self testsItemSelected:ID_TESTS_OTHER_TESTS];
|
||||
}
|
||||
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue