Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement single-line text input #3585

Merged
merged 10 commits into from Nov 13, 2014
@@ -19,7 +19,7 @@ use windowing::{MouseWindowEvent, MouseWindowEventClass, MouseWindowMouseDownEve
use windowing::{MouseWindowMouseUpEvent, MouseWindowMoveEventClass, NavigationWindowEvent};
use windowing::{QuitWindowEvent, RefreshWindowEvent, ResizeWindowEvent, ScrollWindowEvent};
use windowing::{WindowEvent, WindowMethods, WindowNavigateMsg, ZoomWindowEvent};
use windowing::{PinchZoomWindowEvent};
use windowing::{PinchZoomWindowEvent, KeyEvent};

use azure::azure_hl;
use std::cmp;
@@ -43,7 +43,7 @@ use servo_msg::compositor_msg::{Blank, Epoch, FinishedLoading, IdleRenderState,
use servo_msg::compositor_msg::{ReadyState, RenderingRenderState, RenderState, Scrollable};
use servo_msg::constellation_msg::{ConstellationChan, ExitMsg, LoadUrlMsg};
use servo_msg::constellation_msg::{NavigateMsg, LoadData, PipelineId, ResizedWindowMsg};
use servo_msg::constellation_msg::{WindowSizeData};
use servo_msg::constellation_msg::{WindowSizeData, KeyState, Key, KeyModifiers};
use servo_msg::constellation_msg;
use servo_util::geometry::{PagePx, ScreenPx, ViewportPx};
use servo_util::memory::MemoryProfilerChan;
@@ -707,6 +707,10 @@ impl<Window: WindowMethods> IOCompositor<Window> {
self.on_navigation_window_event(direction);
}

KeyEvent(key, state, modifiers) => {
self.on_key_event(key, state, modifiers);
}

FinishedWindowEvent => {
let exit = opts::get().exit_after_load;
if exit {
@@ -878,6 +882,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
chan.send(NavigateMsg(direction))
}

fn on_key_event(&self, key: Key, state: KeyState, modifiers: KeyModifiers) {
let ConstellationChan(ref chan) = self.constellation_chan;
chan.send(constellation_msg::KeyEvent(key, state, modifiers))
}

fn convert_buffer_requests_to_pipeline_requests_map(&self,
requests: Vec<(Rc<Layer<CompositorData>>,
Vec<BufferRequest>)>) ->
@@ -13,14 +13,16 @@ use gfx::render_task;
use layers::geometry::DevicePixel;
use layout_traits::{LayoutControlChan, LayoutTaskFactory, ExitNowMsg};
use libc;
use script_traits::{ResizeMsg, ResizeInactiveMsg, ExitPipelineMsg};
use script_traits;
use script_traits::{ResizeMsg, ResizeInactiveMsg, ExitPipelineMsg, SendEventMsg};
use script_traits::{ScriptControlChan, ScriptTaskFactory};
use servo_msg::compositor_msg::LayerId;
use servo_msg::constellation_msg::{ConstellationChan, ExitMsg, FailureMsg, Failure, FrameRectMsg};
use servo_msg::constellation_msg::{IFrameSandboxState, IFrameUnsandboxed, InitLoadUrlMsg};
use servo_msg::constellation_msg::{LoadCompleteMsg, LoadUrlMsg, LoadData, Msg, NavigateMsg};
use servo_msg::constellation_msg::{NavigationType, PipelineId, RendererReadyMsg, ResizedWindowMsg};
use servo_msg::constellation_msg::{ScriptLoadedURLInIFrameMsg, SubpageId, WindowSizeData};
use servo_msg::constellation_msg::{KeyEvent, Key, KeyState, KeyModifiers};
use servo_msg::constellation_msg;
use servo_net::image_cache_task::{ImageCacheTask, ImageCacheTaskClient};
use servo_net::resource_task::ResourceTask;
@@ -450,6 +452,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
debug!("constellation got window resize message");
self.handle_resized_window_msg(new_size);
}
KeyEvent(key, state, modifiers) => {
debug!("constellation got key event message");
self.handle_key_msg(key, state, modifiers);
}
}
true
}
@@ -761,6 +767,13 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
.any(|current_frame| current_frame.contains(pipeline_id))
}

fn handle_key_msg(&self, key: Key, state: KeyState, mods: KeyModifiers) {
self.current_frame().as_ref().map(|frame| {
let ScriptControlChan(ref chan) = frame.pipeline.script_chan;
chan.send(SendEventMsg(frame.pipeline.id, script_traits::KeyEvent(key, state, mods)));
});
}

fn handle_renderer_ready_msg(&mut self, pipeline_id: PipelineId) {
debug!("Renderer {} ready to send paint msg", pipeline_id);
// This message could originate from a pipeline in the navigation context or
@@ -11,6 +11,7 @@ use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D;
use layers::geometry::DevicePixel;
use layers::platform::surface::NativeGraphicsMetadata;
use servo_msg::constellation_msg::{Key, KeyState, KeyModifiers};
use servo_msg::compositor_msg::{ReadyState, RenderState};
use servo_util::geometry::ScreenPx;
use std::fmt::{FormatError, Formatter, Show};
@@ -58,6 +59,8 @@ pub enum WindowEvent {
FinishedWindowEvent,
/// Sent when the user quits the application
QuitWindowEvent,
/// Sent when a key input state changes
KeyEvent(Key, KeyState, KeyModifiers),
}

impl Show for WindowEvent {
@@ -66,6 +69,7 @@ impl Show for WindowEvent {
IdleWindowEvent => write!(f, "Idle"),
RefreshWindowEvent => write!(f, "Refresh"),
ResizeWindowEvent(..) => write!(f, "Resize"),
KeyEvent(..) => write!(f, "Key"),
LoadUrlWindowEvent(..) => write!(f, "LoadUrl"),
MouseWindowEventClass(..) => write!(f, "Mouse"),
MouseWindowMoveEventClass(..) => write!(f, "MouseMove"),
@@ -50,6 +50,148 @@ pub struct WindowSizeData {
pub device_pixel_ratio: ScaleFactor<ViewportPx, DevicePixel, f32>,
}

#[deriving(PartialEq)]
pub enum KeyState {
Pressed,
Released,
Repeated,
}

//N.B. Straight up copied from glfw-rs
#[deriving(Show)]
pub enum Key {
KeySpace,
KeyApostrophe,
KeyComma,
KeyMinus,
KeyPeriod,
KeySlash,
Key0,
Key1,
Key2,
Key3,
Key4,
Key5,
Key6,
Key7,
Key8,
Key9,
KeySemicolon,
KeyEqual,
KeyA,
KeyB,
KeyC,
KeyD,
KeyE,
KeyF,
KeyG,
KeyH,
KeyI,
KeyJ,
KeyK,
KeyL,
KeyM,
KeyN,
KeyO,
KeyP,
KeyQ,
KeyR,
KeyS,
KeyT,
KeyU,
KeyV,
KeyW,
KeyX,
KeyY,
KeyZ,
KeyLeftBracket,
KeyBackslash,
KeyRightBracket,
KeyGraveAccent,
KeyWorld1,
KeyWorld2,

KeyEscape,
KeyEnter,
KeyTab,
KeyBackspace,
KeyInsert,
KeyDelete,
KeyRight,
KeyLeft,
KeyDown,
KeyUp,
KeyPageUp,
KeyPageDown,
KeyHome,
KeyEnd,
KeyCapsLock,
KeyScrollLock,
KeyNumLock,
KeyPrintScreen,
KeyPause,
KeyF1,
KeyF2,
KeyF3,
KeyF4,
KeyF5,
KeyF6,
KeyF7,
KeyF8,
KeyF9,
KeyF10,
KeyF11,
KeyF12,
KeyF13,
KeyF14,
KeyF15,
KeyF16,
KeyF17,
KeyF18,
KeyF19,
KeyF20,
KeyF21,
KeyF22,
KeyF23,
KeyF24,
KeyF25,
KeyKp0,
KeyKp1,
KeyKp2,
KeyKp3,
KeyKp4,
KeyKp5,
KeyKp6,
KeyKp7,
KeyKp8,
KeyKp9,
KeyKpDecimal,
KeyKpDivide,
KeyKpMultiply,
KeyKpSubtract,
KeyKpAdd,
KeyKpEnter,
KeyKpEqual,
KeyLeftShift,
KeyLeftControl,
KeyLeftAlt,
KeyLeftSuper,
KeyRightShift,
KeyRightControl,
KeyRightAlt,
KeyRightSuper,
KeyMenu,
}

bitflags! {
flags KeyModifiers: u8 {
const SHIFT = 0x01,
const CONTROL = 0x02,
const ALT = 0x04,
const SUPER = 0x08,
}
}

/// Messages from the compositor and script to the constellation.
pub enum Msg {
ExitMsg,
@@ -62,6 +204,7 @@ pub enum Msg {
NavigateMsg(NavigationDirection),
RendererReadyMsg(PipelineId),
ResizedWindowMsg(WindowSizeData),
KeyEvent(Key, KeyState, KeyModifiers),
}

/// Similar to net::resource_task::LoadData
@@ -4280,7 +4280,7 @@ def struct(self):
d = self.dictionary
if d.parent:
inheritance = " pub parent: %s::%s<'a, 'b>,\n" % (self.makeModuleName(d.parent),
self.makeClassName(d.parent))
self.makeClassName(d.parent))
else:
inheritance = ""
memberDecls = [" pub %s: %s," %
@@ -4347,12 +4347,7 @@ def makeClassName(self, dictionary):

@staticmethod
def makeModuleName(dictionary):
name = dictionary.identifier.name
if name.endswith('Init'):
return toBindingNamespace(name.replace('Init', ''))
#XXXjdm This breaks on the test webidl files, sigh.
#raise TypeError("No idea how to find this dictionary's definition: " + name)
return "/* uh oh */ %s" % name
return dictionary.module()

def getMemberType(self, memberInfo):
member, (_, _, declType, _) = memberInfo
@@ -4535,7 +4530,7 @@ def __init__(self, config, prefix, webIDLFile):
'dom::bindings::utils::{DOMJSClass, JSCLASS_DOM_GLOBAL}',
'dom::bindings::utils::{FindEnumStringIndex, GetArrayIndexFromId}',
'dom::bindings::utils::{GetPropertyOnPrototype, GetProtoOrIfaceArray}',
'dom::bindings::utils::{HasPropertyOnPrototype, IntVal}',
'dom::bindings::utils::{HasPropertyOnPrototype, IntVal, UintVal}',
'dom::bindings::utils::{Reflectable}',
'dom::bindings::utils::{squirrel_away_unique}',
'dom::bindings::utils::{ThrowingConstructor, unwrap, unwrap_jsmanaged}',
@@ -5430,7 +5425,8 @@ def InterfaceTypes(config):
def Bindings(config):

descriptors = (set(d.name + "Binding" for d in config.getDescriptors(register=True)) |
set(d.unroll().module() for d in config.callbacks))
set(d.unroll().module() for d in config.callbacks) |
set(d.module() for d in config.getDictionaries()))
curr = CGList([CGGeneric("pub mod %s;\n" % name) for name in sorted(descriptors)])
curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT)
return curr
@@ -1422,6 +1422,9 @@ def dictionaryContainsDictionary(dictMember, dictionary):
self.identifier.name,
[member.location] + locations)

def module(self):
return self.location.filename().split('/')[-1].split('.webidl')[0] + 'Binding'

def addExtendedAttributes(self, attrs):
assert len(attrs) == 0

@@ -1,5 +1,14 @@
--- WebIDL.py
+++ WebIDL.py
@@ -1422,6 +1422,9 @@ class IDLDictionary(IDLObjectWithScope):
self.identifier.name,
[member.location] + locations)

+ def module(self):
+ return self.location.filename().split('/')[-1].split('.webidl')[0] + 'Binding'
+
def addExtendedAttributes(self, attrs):
assert len(attrs) == 0
@@ -3398,6 +3398,9 @@ class IDLCallbackType(IDLType, IDLObjectWithScope):
self._treatNonCallableAsNull = False
self._treatNonObjectAsNull = False
@@ -65,8 +65,12 @@ impl<'a> CustomEventMethods for JSRef<'a, CustomEvent> {
can_bubble: bool,
cancelable: bool,
detail: JSVal) {
self.detail.set(detail);
let event: JSRef<Event> = EventCast::from_ref(self);
if event.dispatching() {
return;
}

self.detail.set(detail);
event.InitEvent(type_, can_bubble, cancelable);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.