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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/chromeos/browser_main_chromeos.h" 6 7 #include "base/lazy_instance.h" 8 #include "base/message_loop.h" 9 10 #include <gtk/gtk.h> 11 12 class MessageLoopObserver : public MessageLoopForUI::Observer { WillProcessEvent(GdkEvent * event)13 virtual void WillProcessEvent(GdkEvent* event) { 14 // On chromeos we want to map Alt-left click to right click. 15 // This code only changes presses and releases. We could decide to also 16 // modify drags and crossings. It doesn't seem to be a problem right now 17 // with our support for context menus (the only real need we have). 18 // There are some inconsistent states both with what we have and what 19 // we would get if we added drags. You could get a right drag without a 20 // right down for example, unless we started synthesizing events, which 21 // seems like more trouble than it's worth. 22 if ((event->type == GDK_BUTTON_PRESS || 23 event->type == GDK_2BUTTON_PRESS || 24 event->type == GDK_3BUTTON_PRESS || 25 event->type == GDK_BUTTON_RELEASE) && 26 event->button.button == 1 && 27 event->button.state & GDK_MOD1_MASK) { 28 // Change the button to the third (right) one. 29 event->button.button = 3; 30 // Remove the Alt key and first button state. 31 event->button.state &= ~(GDK_MOD1_MASK | GDK_BUTTON1_MASK); 32 // Add the third (right) button state. 33 event->button.state |= GDK_BUTTON3_MASK; 34 } 35 } 36 DidProcessEvent(GdkEvent * event)37 virtual void DidProcessEvent(GdkEvent* event) { 38 } 39 }; 40 41 static base::LazyInstance<MessageLoopObserver> g_message_loop_observer( 42 base::LINKER_INITIALIZED); 43 PostMainMessageLoopStart()44void BrowserMainPartsChromeos::PostMainMessageLoopStart() { 45 BrowserMainPartsPosix::PostMainMessageLoopStart(); 46 MessageLoopForUI* message_loop = MessageLoopForUI::current(); 47 message_loop->AddObserver(g_message_loop_observer.Pointer()); 48 } 49 50 // static CreateBrowserMainParts(const MainFunctionParams & parameters)51BrowserMainParts* BrowserMainParts::CreateBrowserMainParts( 52 const MainFunctionParams& parameters) { 53 return new BrowserMainPartsChromeos(parameters); 54 } 55